Java void sendUrgentData() throws SocketException
I am trying to use the sendUrgentData() void to determine if a connection is still alive. The data send through this void will be ignored on the server side, but when a connection is lost, sendUrgentData throws a SocketException on the client side.
This is how is should go. However, after calling sendUrgentData several times it seems to disconnect and throw the SocketException when the connection is still perfectly alive:
java.net.SocketException: Connection reset by peer: send
I checked the network traffic with a sniffer and found that the reset packet was never send. How should I solve this? I'm trying to avoid sending this data the normal way to avoid co开发者_运维技巧rrupting the data currently in the stream.
The data sent won't be ignored, it will be read inline by the server, if it's written in Java. So you are probably causing a protocol error. Connection reset by peer means you have written to a connection that has already been closed by the peer ... probably in response to the protocol error.
Socket#sendUrgentData()
will throw a SocketException
if the underlying implementation does not support sending of urgent data. From memory, the socket exception's message description on Java 1.6 is something like 'urgent data is not supported'.
What platform are you running on (Windows, Linux, etc) ?
What version of Java are you using ?
精彩评论