I have run into a problem with a network server that receives signals from devices my company produces. The device will occasionally reuse the source port that it had just
Building on Nikolai's answer,
Socket s; ... s.setSoLinger(true,0);
would be the equivalent in Java.
EDIT: Another thing you might like to look at would be setReuseAddress(true);