我在Java中实现我自己的proto,它将使用TCP连接的心跳,我也用它来传输消息和文件。 对于客户端,我使用阻塞套接字I / O. 所以这是我计划如何工作...我将设置套接字超时K秒并使心跳保持在间隔T发送消息,以便T <K。如果超时到期,看起来服务器离线对于客户,反之亦然。
心跳是发送字符串的服务器和客户端应答另一个字符串。
我不想浪费大量的带宽,但是如果超时,服务器可能会误认为客户的状态。
什么是良好的K区间? 我在想40秒
PS:字符串是ISO-8859-1中发送的8个字母,所以它的数据很小
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.
What is a good K interval? I am thinking about 40 seconds
PS: the strings are 8 letters sent in ISO-8859-1 so its small data
最满意答案
“K”高度依赖于应用程序的特定流量配置文件(例如,应用程序数据传输的频率)以及应用程序对连接丢失的容忍度(例如,接收器检测连接丢失的速度有多快)。 不幸的是,低开销和快速检测是相反的目标。
这听起来像是你试图解决TCP半开连接问题(RFC 793的含义) 。 如果是这样,如果你不知道“半开放”一词,研究TCP“半开放”可能会指向一些有用的信息,如:
http://www.codeproject.com/Articles/37490/Detection-of-Half-Open-Dropped-TCP-IP-Socket-Conne.aspx
"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.
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:
http://www.codeproject.com/Articles/37490/Detection-of-Half-Open-Dropped-TCP-IP-Socket-Conne.aspx
更多推荐
发布评论