Java 绑定异常
即使重用地址设置为 true,什么会导致 TCP 套接字抛出“java.net.BindException:地址已在使用中”? 仅当应用程序快速重新启动时才会发生这种情况。 在 CentOS 5 Linux 操作系统上运行。
What would cause a TCP socket to throw "java.net.BindException: Address already in use" even when reuse address is set to true? This only occurs if the application is quickly restarted. Running on CentOS 5 linux OS.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这有点解释它:
http://www.beej .us/guide/bgnet/output/html/singlepage/bgnet.html#bind
基本上,在C中,您调用一个名为setsockopt()的函数,并且其中一个参数称为SO_REUSEADDR,它允许您重用该端口。
我在 google 上找到了一些简短的链接,这些链接应该可以帮助您开始了解如何在 Java 中设置等效选项:
http://java.sun.com/j2se/1.4.2/docs/guide/net/socketOpt.html
http://java.sun.com/j2se/1.4.2/docs/api/ java/net/SocketOptions.html
This kinda explains it:
http://www.beej.us/guide/bgnet/output/html/singlepage/bgnet.html#bind
Basically, in C, you call a function called setsockopt(), and one of the parameters is called SO_REUSEADDR, which lets you reuse that port.
I found some brief links on google which should get you started figuring out how to set the equivalent option in Java:
http://java.sun.com/j2se/1.4.2/docs/guide/net/socketOpt.html
http://java.sun.com/j2se/1.4.2/docs/api/java/net/SocketOptions.html
如果您所说的是正确的,您应该能够在循环中捕获此异常,并在几秒钟后重试。 (你不应该这样做,但我听说过一些关于 CentOS 的奇怪的事情)
If what you say is correct you should be able to trap this exception in a loop and try again after a few seconds. (You shouldn't have to do this, but I have heard of a few odd things about CentOS)
如果您的端口或 InetAddress 已被使用并且您想再次使用,则会发生 Java Bind 异常。 因此,释放端口停止程序(如果正在运行)。
否则更改端口
谢谢
迪帕克
Java Bind Exception occurs If either of your port or InetAddress is already used and you want to use once again. So free up the port stop the program if running.
otherwise change the port
Thanks
Deepak