• Post Reply Bookmark Topic Watch Topic
  • New Topic

Detecting socket disconnect (both server/client-side)  RSS feed

 
Alex Rickabaugh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I detect the moment a socket disconnects (whether as a result of a close() on the other side or a break in the link (one client dies, etc.)? isConnected() doesn't seem to be working...
 
Maysam Sorkhabi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure about this but I think if the socket abruptly disconnects it generates an exception, and you can catch that exception. Don't quote me on this tho. Check the API.
 
Catalin Merfu
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try

socket.setKeepAlive( true )
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!