Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

"Address already in use" error when binding a socket in Python

$
0
0

I have a question regarding client socket on TCP/IP network. Let's say I use

try:    comSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)    comSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)except socket.error, msg:    sys.stderr.write("[ERROR] %s\n" % msg[1])    sys.exit(1)try:    comSocket.bind(('', 5555))    comSocket.connect()except socket.error, msg:    sys.stderr.write("[ERROR] %s\n" % msg[1])    sys.exit(2)

The socket created will be bound to port 5555. The problem is that after ending the connection

comSocket.shutdown(1)comSocket.close()

Using wireshark, I see the socket closed with FIN,ACK and ACK from both sides, I can't use the port again. I get the following error:

[ERROR] Address already in use

I wonder how can I clear the port right away so that next time I still can use that same port.

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

setsockopt doesn't seem to be able to resolve the problemThank you!


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>