I am testing an application that uses java sockets, and a lot of times the application doesn't free up a port because it crashes (it's still being developed) before it hits the code to do that. If I want to run the program again, the port that was previously used is not available. I then have to go into the code, change the port number and recompile every time. Is there a way to look for a free port at run-time so that each time I start the program I can find an available port? That way I won't need to constantly change a port number to make things work.