1

I'm working with TCP IP Socket.

Is THIS the simplest way to detect that a client socket connection is broken?

I would be surprised if there is no Java API that detects a dead client and throws an exception. This should be possible at least when the server tries to send a packet to the client from the lack of an ACK response.

Community
  • 1
  • 1
fodon
  • 4,565
  • 12
  • 44
  • 58

1 Answers1

2

TCP protocol does not support any fast means of detecting a broken connection.

This question (and all of it's answers) explain the problem in full: Does a TCP socket connection have a "keep alive"?

So basically yes, that is the simplest way. You need to implement ping-pong packets (aka HearBeat packet) in your application protocol to verify the broken connection properly.

Community
  • 1
  • 1
bezmax
  • 25,562
  • 10
  • 53
  • 84