TCP keep-alive to determine if client disconnected in netty

前端 未结 4 591
日久生厌
日久生厌 2020-12-05 11:48

I\'m trying to determine if a client has closed a socket connection from netty. Is there a way to do this?

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 12:01

    If you read from a connection that has been closed by the peer you will get an end-of-stream indication of some kind, depending on the API. If you write to such a connection you will get an IOException: 'connection reset'. TCP doesn't provide any other way of detecting a closed connection.

    TCP keep-alive (a) is off by default and (b) only operates every two hours by default when enabled. This probably isn't what you want. If you use it and you read or write after it has detected that the connection is broken, you will get the reset error above,

提交回复
热议问题