0

I am writing a simple socket program, but it's not working. Can you please help.

import socket               

s = socket.socket()         
host = socket.gethostname() 
port = 12345             
s.bind((host, port))      

s.listen(5)              
while True:
   c, addr = s.accept()    
   print ('Got connection from', addr)
   c.send('Thank you for connecting')
   c.close()

The below error I use to get.

s = socket.socket()        
TypeError: 'module' object is not callable
Vivek
  • 207
  • 1
  • 4
  • 17
  • Possible duplicate of [TypeError: 'module' object is not callable](https://stackoverflow.com/questions/4534438/typeerror-module-object-is-not-callable) – Aditi Feb 22 '18 at 09:44
  • Is this the exact code you're using? I just copy-pasted it and it worked fine. – wohe1 Feb 22 '18 at 09:46
  • yes, even I copied pasted it from my pycharm. – Vivek Feb 22 '18 at 09:51

1 Answers1

0

Check this:

import socket

print(socket.__file__)
print(socket.socket)

in my environment, result is:

C:\Python27\lib\socket.pyc
<class 'socket._socketobject'>
DDGG
  • 1,171
  • 8
  • 22
  • In my computer result is C:\Users\vWX442280\AppData\Local\Programs\Python\Python36\lib\socket.py – Vivek Feb 22 '18 at 10:18
  • It's ok, so how did you get TypeError from `s = socket.socket() `? Do you have a TeamViewer? – DDGG Feb 22 '18 at 10:23
  • Sorry, I cant use team viewer. – Vivek Feb 22 '18 at 12:29
  • @Vivek You can try installing a clean official version of [python](https://www.python.org/), it may help to solve your problem quickly. – DDGG Feb 22 '18 at 17:26