Java: bind an exception error when using error when not in use (as shown by netstat)

My application creates an outbound connection to the server using a specific source port (in anticipation of firewall issues - for a lightweight system, it will probably need to specify the ports in advance).

My problem is my application is making the connection initially. However, if the connection ever breaks, it will try again, but the socket will receive a BindException saying "address in use". It is not as shown by netstat -pant. It shows that the source port / remote socket pair doesn't exist (i.e. I can't even see it in WAIT mode, the connection just doesn't exist). I will try to contact forever without any success. I would have thought that if it is a problem with a previous connection, it would time out, but it is not. I am getting a binding exception forever.

In my case, I connected to 10.0.1.229:4001 FROM 10.0.1.20:4002. So I used netstat to find the source socket (10.0.1.20:4002) or the remote socket (10.0.1.229:4001), but neither was found after the original connection was broken, indicating that the address Should NOT be used.

Is there something that could cause this connection to remain, although netstat does not report it?

Please note that I am on Linux and I understand that using a random source port will work around my problem, but not fix it.

Please let me know.

Thanks, JBU

+2


source to share


1 answer


close () was not called when some bad things happened - doh!



+2


source







All Articles