使用TCP

编程入门 行业动态 更新时间:2024-10-23 03:21:59
使用TCP-Java套接字的心跳原型的良好超时(Good timeout for heartbeating proto using TCP - Java Sockets)

我在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

更多推荐

本文发布于:2023-08-04 10:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415306.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:TCP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!