0

I'm writing a network application, and have been running into a slight nuisance. I have to wait a period in-between tests, because my server program, even after closing still has the port I'm using "allocated" to it. Furthermore, this makes debugging really hard, since I can't tell what's causing whatever problem I'm dealing with.

For testing purposes, is there a way to free up TCP and UDP ports?

1 Answers1

1

In your python program you need to call the shutdown and close functions for the socket to let the OS know that your program is no longer using it and it will deallocate the socket if nothing is using it after calling those functions. If you fail to call these functions when your program exits, you will end up having to wait on the OS to clean up stale allocated sockets. Even if you force kill the application as the OS still doesn't have a way to know explicitly that its not being used. So, when a program dies and it doesn't close the socket properly, the OS will keep it allocated for a bit of time, until it does its check to see if it is indeed being used, and if it isn't it then deallocates it for use by other programs.

Here is a link that will explain the shutdown and close functions for sockets in python. SO Answer

Frostalf
  • 543