我身边有类似这样的代码Asynchronous Server Socket Example净停止监听套接字
一切都很正常写了一个窗口服务。客户端/服务器通信完美工作。没有问题。当我尝试关闭Windows服务,我不能没有收到以下错误停止服务器套接字监听:
A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied.
我曾尝试以下停止监听的每个组合。但他们都抛出了错误。
listener.Shutdown(SocketShutdown.Both);
listener.Disconnect(true);
listener.Close();
即使发生错误,套接字也会最终释放并关闭。但是,可能需要一分钟才能重新启动我的Windows服务。我需要能够比这更快地循环Windows服务。请让我知道你是否可以帮忙。谢谢...
根据msdn,LingerOption.Enabled == false是默认值,并且表示默认超时时间为_do_逗留。你认为文档有误吗? http://msdn.microsoft.com/en-us/library/system.net.sockets.lingeroption.lingeroption.aspx – Aaron 2012-02-08 23:56:08