C#/。Socket.Shutdown网 [英] c#/.Net Socket.Shutdown

查看:533
本文介绍了C#/。Socket.Shutdown网的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认识到这样的问题有着悠久的历史,但我用这一定是正确的。NET的方式'和方式但它似乎并没有正常工作。

I recognize this type of question has a long history, but the way I am using this must be the correct '.net way' and yet it does not seem to work.

我有,做一个简单的AcceptSocket,做一些东西,socket.send,socket.shutdown,socket.close一个简单的同步IP服务器守护程序。我的客户是另一个平凡的C#应用​​程序,并URLDownloadToFile。

I have a trivial synchronous IP server daemon that does a simple AcceptSocket, do some stuff, socket.send, socket.shutdown, socket.close. My client is another trivial C# app that does URLDownloadToFile.

什么情况是,当时URLDownloadToFilefails的一部分失败,(0x800C0008)..认为其下载资源失败。

What happens is that part of the time URLDownloadToFilefails fails with (0x800C0008) .. thinks its download resource failed.

我的服务器端的顺序是:

My server side end sequence is:

socket.Shutdown(Both);
socket.Close();

如果我更改为

socket.Disconnect();
socket.Close();

(我打开上面sockopt的灵儿真,超时5秒)

(I open the above with sockopt Linger true, timeout 5 secs)

这伟大工程。

我缺少的东西在关机方法..这听起来像魔弹MS要你使用的优雅做最终将发送任何剩余的发送数据的一个出口。

Am I missing something on the Shutdown method.. it sounds like the 'magic bullet' MS wants you to use for gracefully doing an exit that will ultimately send any remaining send data.

眼观,(这不可能是正确的),但好像接近..杀死这可能是正在进行中的关机任何异步处理()。

Grossly, (and this cannot be right) it appears like the close.. kills any async processing that might be in progress from shutdown().

任何想法?

推荐答案

根据的 Socket.Disconnect

如果您需要致电断开不先调用shutdown,你   可以设置DontLinger套接字选项   为false,并指定一个非零   超时间隔,以确保数据   排队等待出站传输   发送。断开再阻塞,直到   数据被发送或直到指定   超时到期。如果设置   DontLinger为false,并指定一个零   超时间隔,关闭释放   连接,并自动丢弃   传出排队数据。

If you need to call Disconnect without first calling Shutdown, you can set the DontLinger Socket option to false and specify a nonzero time-out interval to ensure that data queued for outgoing transmission is sent. Disconnect then blocks until the data is sent or until the specified time-out expires. If you set DontLinger to false and specify a zero time-out interval, Close releases the connection and automatically discards outgoing queued data.

表明,关机是最好的不必要的...

Suggests the Shutdown is at best unnecessary...

这篇关于C#/。Socket.Shutdown网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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