DatagramSocket.receive()因意外的SocketException而失败

时间:2010-12-16 17:20:14

标签: java socketexception

对于未连接和绑定的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也失败了。

您能否告诉我错误的可能原因?

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题 检查套接字的“已关闭”和“connectState”字段。

/*
 * 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;

答案 1 :(得分:0)

  

java.net.SocketException:socket   关闭

这意味着关闭了套接字。