I'm trying to implement a simple example of a distributed producer consumer, and while testing, I always get the following error:
OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
Even though many posts claim that s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
before bind would allow me to ignore the TIME_WAIT, I still get the same exception when trying to connect for a second time.
server.py
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', 4330))
s.listen()
s.accept()
s.close()
client.py
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', 4334))
s.connect((myaddress, 4330))
s.close()