时间:2021-07-01 10:21:17 帮助过:5人阅读
例子1:以服务器断开Socket为例: //判断Socket是否存在且连接正常,存在且连接正常的Socket才运行进行断开操作 if (_cliSock != null && _cliSock.Connected) { //关闭Socket之前,首选需要把双方的Socket Shutdown掉 _cliSock.Shutdown(SocketShutdown.Both); //Shutdown掉Socket后主线程停止10ms,保证Socket的Shutdown完成 System.Threading.Thread.Sleep(10); //关闭客户端Socket,清理资源 _cliSock.Close(); }
例子2:
if (socket != null && socket.Connected && !socket.SendAsync(e))
System.Net.Sockets.Socket SendAsync System.ObjectDisposedException: Cannot access a disposed object.
标签: