Hello,

I'm working on an application that uses a ServerSocket, but it (at points) stops the server thread and restarts it, throwing a java.net.BindException: address already in use exception.

How can I unbind the ServerSocket (.close() is not working to unbind) so I can re-use the same port seconds later?

Note: The thread the ServerSocket is in is redefined when I reload it.

-- Turt2Live

Edited 4 Years Ago by turt2live: n/a

An idea: Connect to the socket so the accept method returns and then have the code exit the thread.

An idea: Connect to the socket so the accept method returns and then have the code exit the thread.

I do that, it's just the way the superclass handles (not mine) my code. The classloader loads, runs the code, then on command unloads and reloads the code. The JVM however seems to be holding onto the bind :/

Can you make a small simple program that compiles, executes and shows the problem (a SSCCE)?

Do you close the socket?

Edited 4 Years Ago by NormR1: n/a

Can you make a small simple program that compiles, executes and shows the problem (a SSCCE)?

Do you close the socket?

While creating this, I found my problem :P

The classloader was not properly unloading the class.

(Bad code on their fault :P)

This question has already been answered. Start a new discussion instead.