Winsock recv关闭后不工作 [英] Winsock recv not working after shutdown

查看:137
本文介绍了Winsock recv关闭后不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让一个简单的winsock程序工作,所以
我创建我的套接字和发送我的数据很好。然后我使用 shutdown(ConnectSocket,SD_SEND)根据msdn,禁用发送数据,但不接收?

但是在我调用 shutdown 后,我的recv函数返回0,而不接收任何数据。

如果我注释掉关机代码,一切都正常工作。



我缺少一些东西?

解决方案

不,这是正常的。另一方通过关闭来响应您的关机。从 recv 的零返回表示正常连接关闭。如果你不想让对方关闭其连接的一半,不要关闭你的。



(你期望另一方做什么它对 recv 的调用返回了零?)


I'm trying to get a simple winsock program working, so I create my socket and send my data just fine. Then I use shutdown(ConnectSocket, SD_SEND) which according to msdn, disables sending data, but not receiving? The example on msdn does this too.

But after I call shutdown my recv function returns 0 without receiving any data.
If I comment out the shutdown code, everything works as it should.

Am I missing something?

解决方案

No, that's normal. The other side responded to your shutdown by shutting down. A zero return from recv indicates a normal connection shutdown. If you don't want the other side to shutdown its half of the connection, don't shut down yours.

(What did you expect the other side to do when its call to recv returned zero?)

这篇关于Winsock recv关闭后不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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