DatagramSocket.receive() 失败并出现意外的 SocketException

发布于 2024-10-08 03:44:16 字数 502 浏览 3 评论 0原文

对于未连接且绑定的 DatagramSocket,接收方法调用(禁用 SO_TIMEOUT)意外失败,并出现以下异常。

java.net.SocketException: socket closed  
 at java.net.PlainDatagramSocketImpl.receive0(Native Method)  
 at java.net.PlainDatagramSocketImpl.receive(PlainDatagramSocketImpl.java:136)  
 at java.net.DatagramSocket.receive(DatagramSocket.java:712)

另外我还没有显式关闭套接字。
此错误发生在带有 JRE-6 的 Windows Server 2008 中。

即使调用 DatagramSocket.close(),在同一套接字地址重新创建新的 DatagramSocket 也会失败。

您能让我知道错误的可能原因吗?

For an unconnected and bound DatagramSocket, the receive method call (with SO_TIMEOUT disabled) failed unexpectedly with the following Exception.

java.net.SocketException: socket closed  
 at java.net.PlainDatagramSocketImpl.receive0(Native Method)  
 at java.net.PlainDatagramSocketImpl.receive(PlainDatagramSocketImpl.java:136)  
 at java.net.DatagramSocket.receive(DatagramSocket.java:712)

Also I've not closed the socket explicitly.
This error occurred in Windows Server 2008 with JRE-6.

Even on calling DatagramSocket.close(), recreating a new DatagramSocket at the same socket address failed too.

Can you please let me know the possible cause(s) for the error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倚栏听风 2024-10-15 03:44:16

我也遇到了同样的问题。
检查套接字的“关闭”和“连接状态”字段。

/*
 * Connection state:
 * ST_NOT_CONNECTED = socket not connected
 * ST_CONNECTED = socket connected
 * ST_CONNECTED_NO_IMPL = socket connected but not at impl level
 */
static final int ST_NOT_CONNECTED = 0;
static final int ST_CONNECTED = 1;
static final int ST_CONNECTED_NO_IMPL = 2;

I have met the same problem.
check the socket's "closed" and "connectState" fields.

/*
 * Connection state:
 * ST_NOT_CONNECTED = socket not connected
 * ST_CONNECTED = socket connected
 * ST_CONNECTED_NO_IMPL = socket connected but not at impl level
 */
static final int ST_NOT_CONNECTED = 0;
static final int ST_CONNECTED = 1;
static final int ST_CONNECTED_NO_IMPL = 2;
迷迭香的记忆 2024-10-15 03:44:16

java.net.SocketException:套接字
已关闭

这意味着已经关闭了套接字。

java.net.SocketException: socket
closed

That means that you have closed the socket.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文