java: 不使用时绑定异常地址使用错误(如netstat所示)
我的应用程序使用特定源端口与服务器建立出站连接(考虑到防火墙问题 - 强化的系统可能需要提前指定端口)。
我的问题是我的应用程序最初建立连接。但是,如果连接中断,它将重试,但套接字将收到 BindException,指出“地址正在使用”。事实并非如此,如 netstat -pant 所示。它表明源端口/远程套接字对不存在(即,我什至没有在等待模式下看到它,连接根本不存在)。我会尝试永远连接,但没有成功。我认为如果是之前的连接挥之不去的问题,它最终会超时,但事实并非如此。我永远得到绑定异常。
就我而言,我从 10.0.1.20:4002 连接到 10.0.1.229:4001。所以我使用netstat来查找源套接字(10.0.1.20:4002)或远程套接字(10.0.1.229:4001),但在初始连接断开后都没有找到,表明该地址不应该被使用。
即使 netstat 没有报告,是否有什么东西会导致此连接保留下来?
请注意,我使用的是 Linux,而且我意识到使用随机源端口可以解决我的问题,但不能解决它。
请告诉我。
谢谢, 吉布
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当某些不好的事情发生时,close() 没有被调用 - 哦!
close() was not being called when certain bad things happened - doh!