java:绑定异常地址在使用时出现错误(如netstat所示) [英] java: bind exception address in use error when it isn't in use (as shown by netstat)

查看:213
本文介绍了java:绑定异常地址在使用时出现错误(如netstat所示)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用特定的源端口与服务器进行出站连接(预计出现防火墙问题 - 硬化系统可能需要提前指定端口)。



我的问题是我的应用程序初始化了连接。但是,如果连接断开,它将再次尝试,但套接字将获得一个BindException,表示正在使用的地址。不是这样,如netstat -pant所示。它表明源端口/远程套接字对不存在(即,我甚至没有看到它在等待模式,连接不存在)。我会尝试连接永远没有任何成功。我会认为如果这是以前的连接留下的问题,它最终会超时,但不会。我永远得到绑定异常。



在我的情况下,我连接到10.0.1.229:4001 FROM 10.0.1.20:4002。所以我正在使用netstat来查找源代码套接字(10.0.1.20:4002)或远程套接字(10.0.1.229:4001),但是在初始连接断开后都没有找到,表示该地址不应该被使用



有没有什么可以导致这种连接,即使netstat不报告?



请注意我在linux上,我也意识到使用随机源端口可以解决我的问题,但不能解决它。



请让我知道。 / p>

谢谢,
jbu

解决方案

close当某些坏事情发生时,不会被呼叫 - doh!


My app makes an outbound connection to a server using a specific source port (in anticipation of firewall problems - a hardened system will probably require ports to be specified ahead of time).

My problem is that my app makes the connection initially. However, if the connection ever breaks it will try again but the socket will get a BindException saying "address in use". This is not the case, as shown by netstat -pant. It shows that the the source port / remote socket pair does not exist (i.e., I'm not even seeing it in a WAIT mode, the connection just doesn't exist). I will try to connect forever without any success. I would think if it were a problem with the previous connection lingering, it would eventually timeout, but it doesn't. I get the bind exception forever.

In my case, I was connecting to 10.0.1.229:4001 FROM 10.0.1.20:4002. So I was using netstat to look for the source socket (10.0.1.20:4002) or the remote socket (10.0.1.229:4001), but neither was found after the initial connection was broken, indicating that the address should NOT be in use.

Is there something that would cause this connection to remain around even though netstat doesn't report it?

Please note I'm on linux and also I realize that using a random source port would work around my issue, but not fix it.

Please let me know.

Thanks, jbu

解决方案

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

这篇关于java:绑定异常地址在使用时出现错误(如netstat所示)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆