Windows套接字send()给出错误10035 [英] Windows Sockets send() gives error 10035

查看:777
本文介绍了Windows套接字send()给出错误10035的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我能够与客户端建立连接并尝试传输大缓冲区(使用大约2 MB的memfile).我正在以16000字节的小数据包发送缓冲区.因此,我有效地调用send()来传输16000字节的每个块,直到所有 数据已发送.我在send()调用之间放置了一次sleep(50)操作,只是给接收者一些时间来收集以前发送的数据.在接收端,我还以16000字节的块为单位执行recv()数据的相同操作.似乎有效 如果我发送一个小缓冲区,则很好,但如果它是一个大缓冲区,则发送操作似乎失败,错误10035.如果我使数据包变小,例如4000字节,它似乎也能正常工作.但这会导致许多sleep()调用,因此传输速度会变慢. 谁能告诉我为什么我收到此错误以及如何解决该问题?

I am able to establish connection with the client and trying to transfer a large buffer (using memfile around 2 MB). I am sending the buffer in small packets of 16000 bytes. So effectively I am calling send() to transfer each chunk of 16000 bytes until all the data are sent. I am putting a sleep (50) operation in between send() calls just to give some time for the receiver to collect the previous data sent. On the receiving side I also do the same thing recv() data in chunks of 16000 bytes. It seems to work fine if i send a small buffer, but if it is a large buffer, the send operation seems to fail with error 10035. If i make the packets smaller say 4000 bytes, it seems to work fine too. But this results in many sleep() calls and so the transfer becomes slower. Can anyone tell me why I am getting this error and how to fix the issue?

ram 

ram 

推荐答案

在winsock中,成功发送意味着将数据复制到TCP内核缓冲区.这并不意味着另一方已收到数据. 10035错误仅在非阻塞套接字上发生.这意味着内核缓冲区已满&没有更多的数据了.你需要 使用"WSAEventSelect" API来确定何时可以发送数据.

In winsock, successful send means the data is copied to the TCP kernel buffer. It doesn't mean the other party has received the data. 10035 error occurs only on non-blocking sockets. It means the kernel buffer is full & no more it can data. You need to use WSAEventSelect  api to determine when its possible to send data.

WSAEventSelect(socket,hEventObject,FD_WRITE);

//从不使用睡眠来决定何时发送数据.

WaitForSingleObject(hEventObject,INFINITE);

//现在您可以调用send

发送(......)


这篇关于Windows套接字send()给出错误10035的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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