使用TCP-Java套接字的心跳原型的良好超时 [英] Good timeout for heartbeating proto using TCP - Java Sockets

查看:149
本文介绍了使用TCP-Java套接字的心跳原型的良好超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java中实现自己的proto,它将使用TCP连接的心跳,我也用它来传输消息和文件。
对于客户端我使用阻塞套接字I / O.
所以这就是我计划如何工作...
我将套接字超时设置为K秒并使心跳保持在间隔T内发送消息,以便T< K.
如果超时到期,看起来服务器对于客户端是离线的,反之亦然。

Im implementing my own proto in Java, it will use a heartbeat over a TCP connection that I also use to transfer messages and files. For the client I am using blocking socket I/O. So here is how Im planning that will work... I will set the socket timeout for K seconds and make the heartbeat stay sending messages in an interval T, so that T < K. If the timeout expires, looks like the server is offline for the client, or vice-versa.

心跳是发送字符串的服务器和客户回答另一个。

The heartbeat is the server sending a String and the Client answering another.

我不想浪费大量的带宽,但是如果超时,服务器可能会误认为客户的状态。

I dont want to waste a lot of bandwidth but with a big timeout the server could be mistaken about the client´s status.

什么是良好的K区间?我想40秒

What is a good K interval? I am thinking about 40 seconds

PS:字符串是ISO-8859-1中发送的8个字母所以它的小数据

PS: the strings are 8 letters sent in ISO-8859-1 so its small data

推荐答案

K高度依赖于应用程序的特定流量配置文件(例如,应用程序数据传输的频率)以及应用程序对连接丢失的容忍度(例如,接收器需要检测连接丢失)。不幸的是,低开销和快速检测是相反的目标。

"K" is highly dependent on the specific traffic profile of the application (e.g. how often is application data transfered) and the application's tolerance for loss of connection (e.g. how quickly does the receiver need to detect the loss of connection). Unfortunately, low overhead and quick detection are opposing goals.

听起来你试图解决 TCP半开连接问题(RFC 793含义)。如果是这样,如果你不知道半开一词,研究TCP半开可能会指向一些有用的信息,如:

It sounds like your trying to address the TCP half-open connection issue (RFC 793 meaning). If so and if you weren't aware of the term "half-open", researching TCP "half-open" might point you toward some useful information like:

< a href =http://www.codeproject.com/Articles/37490/Detection-of-Half-Open-Dropped-TCP-IP-Socket-Conne.aspx\"rel =nofollow> http:// www。 codeproject.com/Articles/37490/Detection-of-Half-Open-Dropped-TCP-IP-Socket-Conne.aspx

这篇关于使用TCP-Java套接字的心跳原型的良好超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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