简体   繁体   中英

why TCP keep-alive packet doesn't trigger I/O event? Is it because no payload or sequence number is 1 less than sequence number of connection

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM