Python server "Only one usage of each socket address is normally permitted"

Solution 1:

On Windows, you can try these steps:

1. check which process uses the port.

# 4444 is your port number
netstat -ano|findstr 4444

you will get something like this:

# 19088 is the PID of the process
TCP    0.0.0.0:4444           *:*                                    19088

2. kill this process

With:

tskill 19088

Or:

taskkill /F /PID 19088

Good luck.

Solution 2:

Enable the SO_REUSEADDR socket option before calling bind(). This allows the address/port to be reused immediately instead of it being stuck in the TIME_WAIT state for several minutes, waiting for late packets to arrive.

s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)