Link to home
Start Free TrialLog in
Avatar of warba
warbaFlag for Canada

asked on

Re-use socket/port after close() ?

From the Java docs I see the close() method saying:

public void close()
....
Once a socket has been closed, it is not available for further networking use (i.e. can't be reconnected or rebound). A new socket needs to be created.
...

Could someone explain if/why this is true, or is there any way to re-use a port after it has been closed? (i.e., by lowering a time-out value, or setReuseAddress?)

I am not a Java programmer (so please be kind in your answer), but we make use of another language that uses Java libraries for networking and we find that we can only open and close a given connection about 1024 times before a ports unavailable error occurs; even though ALL ports are definitely closed, they are not accessible to the process (netstat shows them in use). As soon as the process is killed, then ports are immediately available for use.

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial