I am new to Python and I am trying to write a Server program. However, when it comes time for the server to accept the socket connection, it won’t and I have to terminate the program with
File "test.py", line 12, in <module>
client_socket, address = server_socket.accept()
File "/usr/lib/python2.6/socket.py", line 195, in accept
sock, addr = self._sock.accept() `
I’m pretty sure it is saying that something is not matching up but I cannot find out where it is not doing so. My server program is below:
import socket
import os
server_address = '10.1.1.2'
#while 1:
# os.system('netcat -l 3333')
serversocket = socket.socket( socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind ((socket.gethostname(), 3333))
serversocket.listen(1)
serversocket, client_addr = serversocket.accept()
print client_addr
serversocket.close()
Thank you for you help!
I figured it out. Instead of socket.gethostname() I needed to be server_address in that spot. Thats why I couldn’t connect to the server in the first place and always had to kill it with ^C