我身邊有類似這樣的代碼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