DatagramSocket.receive () error with unexpected SocketException

For an unbound and bound DatagramSocket, the call to the receive method (with SO_TIMEOUT disabled) unexpectedly ended 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 did not explicitly close the socket.
This error occurred in Windows Server 2008 using JRE-6.

Even when calling DatagramSocket.close (), it was also not possible to recreate the new DatagramSocket with the same socket address.

Could you tell me the possible causes of the error?

+3
source share
2 answers

I ran into the same problem.
check the socket fields "closed" and "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
source

java.net.SocketException:

, .

0

Source: https://habr.com/ru/post/1780721/


All Articles