in C# when a sockets connection is terminated the other node is informed of this before terminating the link thus the remaning node can update the connection status.
in Java when i terminate a communication link the other node keeps reporting the connection as valid.
do i need to implement a read cycle (makes sense) that reports the connection as lost when it recieves a -1 during read (in C# this is 0 i think)?
thank you for your insight.
EDIT: thanks to you both. as i suspected and mentioned in my post that an additional check is required to confirm the connected state of a connection.
In java, you find out about the other end of the socket being closed only when you read/write to/from the socket, or query the input stream state (e.g.
InputStream.available()). I don’t think there is any asynchronous notification that the other end is closed.How are you testing that the socket is still open?
You can poll the
InputStream.available()method and if that returns -1, you know the socket is closed. Of course, you can also read data, if that fits with your usage.See InputStream.available()