Ronyco Ronyco - 1 year ago 89
Python Question

Only one usage of each socket address is normally permitted Python

I wrote a basic program in to create a socket with a server and a client. But the problem is that when I run the code, it gives me an error saying that only one usage of each socket address is normally permitted. So I think the problem is due to the port, I changed the port and it still don't work. How do I get this to work?

This is my code :


import socket
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
print "Server is ready to receive data..."
client, address = sock.accept()
msg = client.recv(1024)
print msg


import socket
connection_to_server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
msg = raw_input("Please enter a content :")

Thanks for your help !

Answer Source

I think there's a fundamental misunderstanding of how sockets work here.

The socket.bind() call is used to start "listening" on a particular socket. Only the server needs to do this. The client will then use socket.connect to connect to this socket.

Your client and server both try to start listening on the same socket, which is as the error message suggests, not allowed.

You should go through the Socket Programming HOWTO before proceeding further.