My cleanup code is a bit dodgy at the moment, and I’m trying to debug it but unfortunately my program crashes before it gets to the cleanup bit because the socket wasn’t cleaned up properly last time around. Restarting eclipse between runs cleans up the socket, but that’s obviously a far less than ideal situation.
Is there any way to programmatically clean up a socket that the previous execution left hanging?
There’s no way to ‘clean up’ that socket since it’s already gone, but you can allow reuse of the same network address using SO_REUSEADDR on the original app’s socket. This should allow a quickly-arriving successor to the dead app to avoid failure, assuming the old app is really gone.