我需要心跳来保持 TCP 连接打开吗? [英] Do I need to heartbeat to keep a TCP connection open?

查看:34
本文介绍了我需要心跳来保持 TCP 连接打开吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个通过 TCP/IP 通信的组件.组件 A 充当服务器/侦听器,组件 B 是客户端.两人应尽快沟通.任何时候都只能有一个连接(尽管这与这个问题无关).我公司的一位高级开发人员说我需要在两个组件之间使用应用程序级别的心跳来确保连接保持打开状态.

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 possible. There can only ever be one connection at any time (though that is aside to this question). A senior developer at my company has said I need to use application level heartbeats between the two components to ensure the connection stays open.

我认为连接会通过 TCP/IP 保持打开状态,但我已经阅读了许多博客/网站,他们说在这些应用程序之间进行心跳是非常标准的做法.

I thought the connection stays open with TCP/IP but I've read a number of blogs/sites saying it's pretty standard practice to heartbeat between these applications.

我知道组件 A 检测组件 B 的部分原因是,如果组件 B 出现通信问题(链接断开或组件 B 未运行),它可以通知支持人员.是否出于任何其他原因需要心跳?例如确保经常有东西在管道中"以使其保持打开状态?

I know part of the reason component A heartbeats component B is so it can inform support if there are communications problems with component B (either the link is down or component B is not running). Are heartbeats needed for any other reason? Such as to ensure there is frequently something "in the pipe" to keep it open?

组件 A 当前每 20 秒对组件 B 进行心跳检测,如果在 120 秒内没有从组件 B 收到任何消息,则关闭连接.然后,假设如果链接断开,组件 B 将定期尝试重新连接,它会继续侦听连接.这工作成功.

Component A currently heartbeats component B every 20 seconds and closes the connection if nothing is received back from component B in 120 seconds. It then resumes listening for connections under the assumption that component B will periodically try a reconnect if the link is broken. This works successfully.

重申我的问题:保持 TCP/IP 连接活动是否需要心跳?

To reiterate my question: Are heartbeats necessary to keep a TCP/IP connection alive?

推荐答案

连接应该无论如何都保持打开状态,但是是的,经常看到协议实现心跳以帮助检测死连接,IRC例如,使用 PING 命令.

The connection should remain open regardless but yes it's often common to see protocols implement a heartbeat in order to help detect dead connections, IRC with the PING command for example.

这篇关于我需要心跳来保持 TCP 连接打开吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆