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

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.