3

when i try to create af socket with the import socket module like:

from socket import *
from thread import *
responseok = bytes('ok')
HOST = ''
PORT = 4445
c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
c.bind((HOST, PORT))
c.listen(10)
def clientthread(conn):
 dat = conn.recv(1024)
 data = str(dat)
 print data
 conn.close()
while 1:
conn, addr = c.accept()
start_new_thread(clientthread ,(conn,))
c.close()

i get the following error:

Traceback (most recent call last):
 File "C:\Users\MikeClaudi\My Documents\LiClipse Workspace\server2\src\socket.py", line 6, in <module>
from socket import *
 File "C:\Users\MikeClaudi\My Documents\LiClipse Workspace\server2\src\socket.py", line 11, in <module>
c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

NameError: name 'socket' is not defined

asked Dec 17, 2014 at 11:18

1 Answer 1

3

If you use

from socket import *

then you have to do

c = socket(socket.AF_INET, socket.SOCK_STREAM)

But in order to not confuse the two socket (module and class), just

import socket

and then

c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
answered Dec 17, 2014 at 11:20
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.