简体   繁体   English

C LINUX \\ WINSOCK-检查发送中的FIN数据包

[英]C LINUX\WINSOCK- check FIN packet in Send

I am trying to understand how to avoid the following scenario: 我试图了解如何避免以下情况:

  1. A client kills its process. 客户杀死了它的过程。 A FIN message is sent to server. FIN消息发送到服务器。
  2. Server receives the FIN message from the client. 服务器从客户端接收FIN消息。
  3. A milisecond after the server receives the FIN message, the server uses the send message, and sends information to the client. 服务器收到FIN消息后一毫秒,服务器使用发送消息,并将信息发送给客户端。

Using the C API- can the server know what packets are acknowledged by the client? 使用C API,服务器可以知道客户端确认了哪些数据包吗?

If so- what are the commands in Linux\\Winsock? 如果是的话,Linux \\ Winsock中的命令是什么?

This question comes up periodically. 这个问题会定期出现。 Short answer: The TCP layer in the OS intentionally does not pass up "acks" (acknowledgement of receipt) to the application layer. 简短的答案:操作系统中的TCP层不会故意将“确认”(确认收货)传递给应用程序层。 And if it did, it would be the rope you would hang yourself by. 如果这样做的话,那将是您可以自在悬吊的绳索。 While TCP is considered "reliable", it doesn't actually have a way to indicate if the application code above it has actually processed the received bytes. 尽管TCP被认为是“可靠的”,但它实际上没有办法表明其上方的应用程序代码是否已实际处理了接收到的字节。

You mentioned "packets", but that is a very ambiguous term. 您提到了“数据包”,但这是一个非常模糊的术语。 Your socket application may have the notion of "messages" (not packets), but TCP does not have the concept of a packet or even a message. 您的套接字应用程序可能具有“消息”(不是数据包)的概念,但是TCP没有数据包甚至消息的概念。 It sends byte "streams" that originate from your application code. 它发送源自您的应用程序代码的字节“流”。 TCP segmentation, IP fragmentation, and other factors will split your message up into multiple packets on the wire. TCP分段,IP分段和其他因素会将您的消息拆分为网络上的多个数据包。 And TCP has no knowledge of what IP packets make up the entire application message. TCP不知道什么IP数据包构成了整个应用程序消息。 (Common socket fallacy - many developers erroneously believe a "send" corresponds to an identically sized "recv" on the other side). (常见的套接字谬误-许多开发人员错误地认为“发送”对应于另一侧大小相同的“ recv”)。

So the only code that can acknowledge success receipt of a message is the socket application itself. 因此,可以确认消息成功接收的唯一代码是套接字应用程序本身。 In other words, your client/server protocol should have its own system of acknowledgements. 换句话说,您的客户端/服务器协议应具有其自己的确认系统。

I can't speak for Linux, but under Windows if a process is killed with established connections open, those connections are forcibly (hard) reset. 我不能说Linux,但是在Windows下,如果某个进程在建立的连接打开的情况下被杀死,则这些连接将被强制(硬)重置。 The peer will receive a RST, not a FIN, and further communication over the connection is impossible. 对等方将收到RST,而不是FIN,并且无法通过该连接进行进一步的通信。

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

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