public void StopMe() { try { if (!_isStop) { if (this.TcpIsCanUse())//发送一条对服务器的通告 { uint seq = Tools.GetSequence_Id(); CMPP_Terminate t = new CMPP_Terminate(); this.Send(t.Encode()); this.HeartStop(); SMSLog.Log("=SocketClient==》StopMe()==HeartStop=="); } MyTools.WaitTime(10); //等待1000ms,告知服务器 _isStop = true; if (_socket != null) { _socket.Shutdown(SocketShutdown.Both); _socket.Close(); _socket = null; } SMSLog.Log("=SocketClient==》StopMe()==_socket=="); } } catch (Exception ex) { SMSLog.Log("=SocketClient==》StopMe()异常:" + ex.Message); } }
public void Close() { try { if (_socket != null) { try { uint seq = Tools.GetSequence_Id(); CMPP_Terminate t = new CMPP_Terminate(); this.Send(t.Encode()); SMSLog.Debug("===Close==发送退出命令======"); // MyTools.WaitTime(100); Thread.Sleep(100); } catch (Exception ex) { SMSLog.Error("Close Error", ex.Message); } _socket.Shutdown(SocketShutdown.Both); _socket.Close(); } } catch { } }