Do I need to heartbeat to keep a TCP connection open?

前端 未结 15 1991
温柔的废话
温柔的废话 2020-11-27 09:56

I have two components that that communicate via TCP/IP. Component A acts as a server/listener and Component B is the client. The two should communicate as quickly as possi

相关标签:
15条回答
  • 2020-11-27 10:23

    The connection will remain open - there is no need to implement a heartbeat, and most applications that use sockets do not do so.

    0 讨论(0)
  • 2020-11-27 10:26

    As many others have noted, the TCP connection will stay up if left to its own devices. However, if you have a device in the middle of the connection that tracks its state (such as a firewall), you may need keepalives in order to keep the state table entry from expiring.

    0 讨论(0)
  • 2020-11-27 10:26

    What you call a heartbeat is useful when trying to set timeouts. Your socket may appear open, but the person on the other end may be suffering a BSOD. One of the easiest ways to detect defunct clients/servers is to set a timeout and make sure a message is received every so often.

    Some people call them NOOPs(No Ops).

    But no, they are not necessary to keep connection alive, only helpful to know what the status is.

    0 讨论(0)
提交回复
热议问题