How to manually close a TCP socket

351865 pts.
Tags:
Networking
Socket
TCP
My partner and I currently have a Python app that opens A TCP socket that communicates with another Python app on a separate host. Every once in a while, we notice the program either errors or we kill it. When that happens, the socket is still open for some time. Every time after we go to run the program, we get the following error:
socket.error: [Errno 98] Address already in use
Our program is using the same port, which means the socket is still open. But we checked and we're pretty sure it's not running in the background and our address is still in use. Is there a way we can manually close the socket to we can reuse it?

Answer Wiki

Thanks. We'll let you know when a new response is added.

This can be achieved through close() function. Though you close() a socket, you can’t use it instantly. Because it will be in a TIME_WAIT state.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following