Most common ways of check if a socket connection to server was broken is by send a heartbeat message to server. However, for application that connect to server that do not support heardbeat, we can check connection by listen to the InputStream:
('is' refer to java.io.InputStream)
int bytesRead = is.read(receiveBuffer, 0, 1024);
// this is the trick to identify connection drop
if(bytesRead == -1){
throw new IOException("byteRead = -1, Connection closed.");
}
1 comment:
thanks alot guy
it works for me properly
Post a Comment