I am familiar with socket programming in C but not so much in Java. In the sockets C interface there is a socket event received by the socket server when a client disconnects (does a shutdown or close). But I can't find the equivalent for Java.net.
How would I code this in Java? Do I get an exception of a certain type? Something else?
Your server will certainly get an exception if it tries to send data to a client which has already disconnected from the connection. I don't think the server gets notified until then, though. However it shouldn't be too hard to set up an experiment to find out for sure, should it?
Angus Comber
Ranch Hand
Joined: Jul 16, 2011
Posts: 90
posted
0
Paul Clapham wrote:Your server will certainly get an exception if it tries to send data to a client which has already disconnected from the connection. I don't think the server gets notified until then, though. However it shouldn't be too hard to set up an experiment to find out for sure, should it?
Looking on the web that was the impression I got, but wanted to check. Not getting such an event is a bit of a pain. I could set a timestamp for client activity and set a timer to periodically check if timestamp > a threshold and then send a short message to client to check - I guess that would work.