心跳方向和确认
我们有一个 Java 客户端服务器应用程序,具有使用 TCP/IP 的自定义协议。我们发现由于死套接字连接问题,有必要在协议中使用心跳。
从一开始我们就一直有从客户端到服务器的心跳,服务器会做出确认响应。
我们最近与客户遇到了超时问题,在分析代码后提出了几个我不确定的问题。
1 - 什么方向最适合心跳,我认为我们选择“客户端到服务器”,因为它承担服务器的负载。 我正在考虑将其更改为“服务器到客户端”,但是我们可以控制客户端和服务器代码,因此我们不需要太担心浪费客户端时间。
2 - 是否有必要确认心跳来证明两个方向的连接都处于活动状态?
非常感谢
We have a Java client server application with a custom protocol using TCP/IP. We have found it necessary to use a heartbeat within the protocol due to dead socket connection issues.
We have had the heartbeat since the beginning going from client to server with the server responding with an acknowledgment.
We have recently had a timeout issues with the clients, and after analysing the code have come up with a couple of questions I am unsure about.
1 - What direction is best for a heartbeat, I think we chose 'client to server' as it takes the load of the server.
I was thinking of changing it to 'server to client' however we have control of both the client and server code, so we don't need worry so much about time wasting clients.
2 - Is it necessary to acknowledge heartbeats to prove the connection is alive in both directions?
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为任一方向的任何流量都应该足以使其保持活动状态,但用“ping”和“pong”响应也没什么坏处。传统上,客户端发送心跳,服务器将负责关闭无响应的客户端,因此您所拥有的听起来是正确的。
您是否尝试过将超时设置为零?是否是网络设备干扰了您的套接字连接超时?
I'm thinking any traffic in either direction should be enough to keep it alive but it doesn't hurt to respond with a "ping" with a "pong". Traditionally the client sends the heartbeat and the server will be responsible to shutting down unresponsive clients so what you have sounds right.
have you tried setting the timeout to zero? Could it be network devices that are interfering with your socket connection timeout?