简体   繁体   English

发送/接收套接字阻止问题

[英]Send/Recv Socket Blocking Issues

another question about my beloved sockets. 关于我心爱的插座的另一个问题。 I'll first explain what my case is. 我先解释一下我的情况。 After that I will tell you whats bothering me. 之后,我将告诉您困扰我的事情。

I have a client and a server. 我有一个客户端和一个服务器。 Both Applications are written in C++ with the winsock2 implementation. 这两个应用程序均使用C ++编写,并带有winsock2实现。 The connection runs over TCP and WLAN. 连接通过TCP和WLAN运行。 WLan is very important, because its probably causing the issue and is definetly going to be the communicationchannel. WLan非常重要,因为它可能会引起问题,并且肯定会成为通信渠道。

I'm connecting two sockets to the server. 我正在将两个套接字连接到服务器。 A SendSocket and a ReceiveSocket. 一个SendSocket和一个ReceiveSocket。 I'm constantly sending video data to the server through the sendsocket. 我一直在通过sendocket向服务器发送视频数据。 The data is processed and gets send back to the client and gets displayed. 数据被处理并被发送回客户端并被显示。 Each socket got his own thread. 每个套接字都有自己的线程。

The Videodata is encoded, so I achieve like 500kB/s. Videodata已编码,因此达到了500kB / s的速度。 Lets see this rate as fixed, without explanation. 让我们将此速率视为固定值,无需说明。

Perfect communication viewed by the client: 客户认为完美的沟通:

Send Data
Recv Data
Send Data
Recv Data
...

This is for like 100 frames the case. 这种情况适用于100帧的情况。

But every couple of frames, the stream freezes for like 4 frames and continues after that. 但是每隔几帧,流就会冻结约4帧,然后继续。 (4 frames are like 500ms) (4帧像500ms)

Thats the issue, i'm facing. 那就是问题,我正面临着。

What happens to the stream is the following: 该流将发生以下情况:

Send Data
Recv Data
Send Data
Send Data
Send Data1 -> blocked send
Recv Data
Recv Data
Send Data2 -> not blocked anymore.

The Data gets properly sent on server side. 数据已正确发送到服务器端。

Since WLan is not duplex (as far as I know), I thought, that the send calls are prioritized for some reason. 由于WLan不是双工的(据我所知),所以我认为,出于某种原因,发送调用被优先处理。 And after that the Receive calls are prioritized, so the send call blocks until the recv calls are done. 然后,对接收呼叫进行优先排序,因此发送呼叫将阻塞,直到完成接收呼叫为止。

Maybe you can tell me, what is happening in the lower layer, which could cause the problem. 也许您可以告诉我,下层正在发生什么,这可能会导致问题。 Btw. 顺便说一句。 I'm definetly not sure, if its not just a bandwidth issue, but I thought WLAN should be able to handle 500kB/s. 我绝对不确定,这不仅是带宽问题,而且我认为WLAN应该能够处理500kB / s。 This 500kB/s are both upstream and downstream together. 此500kB / s同时位于上游和下游。 Important notice: If I set the framerate to a factor of 1/5, it does not fix the issue. 重要说明:如果将帧速率设置为1/5的因子,则不能解决问题。

I know it's hard to fix this issue with this insight. 我知道很难用这种见解解决此问题。 I would be happy, if you could share your knowledge, so I may be able to fix it myself. 如果您可以分享您的知识,我将很高兴,因此我可以自己解决问题。

EDIT: Its perfectly fine, if the client recv hangs a litte. 编辑:如果客户端Recv挂了一个小字,它就很好。 But it must not block the send. 但是它一定不能阻止发送。 The server needs data continuosly. 服务器连续需要数据。

A blocked send means either that the socket send buffer is full, which means either (a) that the socket receiver buffer at the receiver is full, which means the receiver isn't reading as fast as you're sending; 发送阻塞意味着套接字发送缓冲区已满,或者(a)接收方的套接字接收方缓冲区已满,这意味着接收方的读取速度不如发送时快; or else (b) that there are network losses that are causing the sender to retry. 否则(b)存在导致发送方重试的网络丢失。 In either case there is nothing you can do about it at the sending end. 无论哪种情况,在发送端您都无能为力。

Someone is bound to mention non-blocking I/O as a solution, but it isn't: at the point where a blocking sender blocks, a non-blocking sender will get -1 from send() witch 'errno == EAGAIN/EWOULDBLOCK', which doesn't solve the actual problem at all. 一定有人会提到非阻塞I / O作为解决方案,但事实并非如此:在阻塞发件人阻塞的那一刻,非阻塞发件人将从send()中获得-1巫婆'errno == EAGAIN / EWOULDBLOCK”,根本无法解决实际问题。

Alright then. 那好吧 It was definetly a wlan issue. 这绝对是一个WLAN问题。 I tested over the eduroam wlan at my university. 我在大学里通过eduroam wlan测试。 I don't know, if anybody knows it. 我不知道,是否有人知道。 Now I tested it with a simple router and it worked fine. 现在,我用一个简单的路由器对其进行了测试,并且工作正常。 Seems like the eduroam wlan does have some trouble with bandwidth or direction changes. 好像eduroam wlan确实在带宽或方向更改方面有些麻烦。 I won't look into that... 我不会调查...

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

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