简体   繁体   English

在TCP / IP套接字中,服务器如何知道客户端正在忙并且没有接收数据?

[英]In TCP/IP sockets, how would the server know that a client is busy and not receiving data ?

In TCP/IP sockets, how would the server know that a client is busy and not receiving data ? 在TCP / IP套接字中,服务器如何知道客户端正在忙并且没有接收数据?

My solution: 我的解决方案:

Use connect(), 使用connect(),

I am not sure. 我不确定。

thanks 谢谢

In TCP/IP sockets, how would the server know that a client is busy and not receiving data 在TCP / IP套接字中,服务器如何知道客户端正在忙并且没有接收数据

If a TCP is constantly pushing data that the peer doesn't acknowledge, eventually the send window will fill up. 如果TCP不断推送对等方不认可的数据,则最终发送窗口将填满。 At that point the TCP is going to buffer data to "send later". 此时,TCP将缓冲数据以“稍后发送”。 Eventually the buffer size will be reached and send(2) will hang (something it doesn't usually do). 最终将达到缓冲区大小,并且send(2)将挂起 (通常不执行此操作)。

If send(2) starts hanging it means the peer TCP isn't acknowledging data . 如果send(2)开始挂起,则意味着对等TCP未确认data

Obviously, even if the peer TCP accepts data it doesn't mean the peer application actually uses it. 显然,即使对等TCP接受数据,也并不意味着对等应用程序实际使用了它。 You could implement your own ACK mechanism on top of TCP , and it's not as unreasonable as it sounds. 您可以在TCP之上实现自己的ACK机制,这听起来并不合理。 It would involve having the client send a "send me more" message once in a while. 这将涉及让客户端不时发送“发送给我更多”的消息。

A client will almost always receive your data, by which I mean the OS will accept the packets and queue them up for reading. 客户端几乎总是会收到您的数据,这意味着操作系统将接受数据包并将其排队等待读取。 If that queue fills up, then the sender will block (TCP, anyways). 如果该队列已满,则发送方将阻止(始终使用TCP)。 You can't actually know the activity of the client code. 您实际上无法知道客户端代码的活动。 Pretty much your only option is to use timeouts. 几乎唯一的选择是使用超时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM