1

I want to let my application layer notified when my server received Keep Alive Packet. I am wondering what's the reason Keep Alive packet doesn't trigger I/O event. Is it because the TCP Keep Alive packet has no data or sequence number is 1 less than the sequence number of connection.

I did some test to let my client sent Keep Alive Packets. My server use epoll but didn't get triggered.

I am also wondering if I pad one byte to Keep Alive packet data/payload, will my application get notified/ I/O event / Epoll triggered?

dbush
  • 205,898
  • 23
  • 218
  • 273
user292048
  • 15
  • 6
  • 3
    The TCP keep-alive is below the application in the network stack. The application doesn't care about that. To it, the lower layers are magic. – Thomas Jager Jun 06 '19 at 18:45
  • 1
    Some code would be in order here – orhtej2 Jun 06 '19 at 18:46
  • Possible duplicate of [how to detect TCP keep alive packets and keep connection open](https://stackoverflow.com/questions/56434706/how-to-detect-tcp-keep-alive-packets-and-keep-connection-open) – Shawn Jun 07 '19 at 01:26
  • @orhtej2 No it wouldn't. It's a general question about TCP. – user207421 Aug 18 '19 at 02:41

1 Answers1

4

You should not be surprised by that. For example, you are not notified of RST packets either.

Those are transport-level messaging details. On the application level, TCP gives you stream of bytes, independent of low-level details. If you want to have application-level heartbeats, you should implement them on the application level protocols.

Your latest edit seems to be stemming from some sort of confusion. You can't add data into Keep Alive packets, for two reasons:

  • First, they are sent by network layer and application doesn't have control over them (beside timeouts)
  • More importantly, if by some (dark) magic you manage to interfere with network layer (say, you patch your kernel :) and start putting data into them, they will stop being keep alive packets, and will become normal data packets, carrying data. Than, of course, your receiver will be notified of the data, which will become part of the message stream.
SergeyA
  • 61,605
  • 5
  • 78
  • 137
  • @user292048 how would you do that? Those are sent by network layer and you can't interfere with them. – SergeyA Jun 06 '19 at 18:57
  • @user292048 moreover, if you manage to put data into Keep Alive packets, they would become normal data packets, so of course, you will be notified. – SergeyA Jun 06 '19 at 19:07
  • Not that you could. It's only sent when there has been no activity for the keepalive period. NB You most certainly are notified of RST packets, but via an error, not via data. – user207421 Aug 18 '19 at 02:42