[英]c++ Winsock send,recv -how they work
I'm new in network programming and I'm trying to understand how functions like send and recv work under the hood in a TCP connection.I know that in a connection between a client and a server for example ,when the client manage to send a message to the server ,the message is split in different packages and at it's arrival,the server part checks to see if the sum of the packages is the same as it was before sending,and if is ok it sends a message back to the client as an approval.If a problem appears the client resends the message. 我是网络编程的新手,我正在尝试理解发送和recv等功能如何在TCP连接下工作。我知道在客户端和服务器之间的连接中,例如,当客户端设法发送时一条消息发送到服务器,消息被分成不同的包,当它到达时,服务器部分检查包的总和是否与发送前相同,如果没有,它会将消息发送回客户端作为批准。如果出现问题,客户端将重新发送该消息。
What I don't understand is that if you send a message from the client and you sleep the server for 10 seconds,you can still do what you want in the client,like the send function is executing in another thread ,or if you use multiple times send function in these 10 seconds,the message arrives as a combination of the messages used in that time. 我不明白的是,如果你从客户端发送一条消息,你在服务器上睡10秒钟,你仍然可以在客户端做你想做的事情,比如send函数在另一个线程中执行,或者你使用在这10秒内多次发送功能,消息作为该时间内使用的消息的组合到达。
If anyone can explain the situation ,I'll be very grateful ! 如果有人能解释一下情况,我将非常感激!
This is implemented by the TCP/IP networking stack of your operating system. 这是由您的操作系统的TCP / IP网络堆栈实现的。
The TCP/IP stack ... TCP / IP堆栈......
In the case you wrote the client is filling the sender OS's send buffer and the receiver OS's receive buffer. 在您编写的情况下,客户端正在填充发送方OS的发送缓冲区和接收方OS的接收缓冲区。 Your client can send non-blocking until both buffers are full.
您的客户端可以发送非阻塞,直到两个缓冲区都已满。 Then it will block until the server calls recv again.
然后它将阻塞,直到服务器再次调用recv。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.