交流电插座:不发送等待recv的结束? [英] C socket: does send wait for recv to end?

查看:117
本文介绍了交流电插座:不发送等待recv的结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows上使用阻断C插座。
我用它们来从服务器到客户端,反之亦然发送数据的更新。我在一个较高的频率(每100ms)发送更新。请问发送()函数将等待收件人的recv()结束前接收到的数据?

I use blocking C sockets on Windows. I use them to send updates of a data from the server to the client and vice versa. I send updates at a high frequency (every 100ms). Does the send() function will wait for the recipient recv() to receive the data before ending ?

我认为不是我的理解以及男人页:

I assume not if I understand well the man page:

成功完成的send()并不能保证邮件的传递的。

"Successful completion of send() does not guarantee delivery of the message."

所以,如果一个运行10个会发生什么发送() OCCURENCES而另一只具有完整的1 的recv()

So what will happen if one is running 10 send() occurences while the other has only complete 1 recv() ?

我是否需要使用这样一些应答系统的?

Do I need to use so some sort of acknowledgement system ?

推荐答案

让我们假设你使用的是TCP。当你调用发送,你发送的数据立即被放置在传出队列,并发送,然后成功完成。但是,如果发送无法放置在传出队列中的数据,发送将返回一个错误。

Lets assume you are using TCP. When you call send, the data that you are sending is immediately placed on the outgoing queue and send then completes successfully. If however, send is unable to place the data on the outgoing queue, send will return with an error.

由于TCP是一个保证的交付协议,只能使用一次,确认已被远程终端接收到取消了对即将离任的队列中的数据。这是因为数据可能需要的,如果没有应答已在时间已经接收到重发。

Since Tcp is a guaranteed delivery protocol, the data on the outgoing queue can only be removed once acknowledgement has been received by the remote end. This is because the data may need to be resent if no ack has been received in time.

如果远端疲软,传出队列将填补了数据和发送,然后将阻塞,直到有空间来放置在传出队列中的新数据。

If the remote end is sluggish, the outgoing queue will fill up with data and send will then block until there is space to place the new data on the outgoing queue.

的连接但是可能会失败是这样一种方式,也没有办法任何进一步的数据可以被发送。虽然一旦TCP连接已被关闭,任何进一步的发送将导致一个错误,用户无法知道有多少数据并实际上使之到另一侧的方式。 (据我所知,没有办法从套接字检索TCP簿记用户应用程序的)。因此,如果需要接收数据的确认,你应该实现这个的应用水平。

The connection can however fail is such a way that there is no way any further data can be sent. Although once a TCP connection has been closed, any further sends will result in an error, the user has no way of knowing how much data did actually make it to the other side. (I know of no way of retrieving TCP bookkeeping from a socket to the user application). Therefore, if confirmation of receipt of data is required, you should probably implement this on application level.

有关UDP,我想不用说,报告有什么或尚未收到的一些方法是必须的。

For UDP, I think it goes without saying that some way of reporting what has or has not been received is a must.

这篇关于交流电插座:不发送等待recv的结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆