public bool Stop() { var ret = false; if (_mIsStarted) { _listenSocket.Close(); _mDaemonThread.Close(); _listenSocket = null; _mDaemonThread = null; _mIsStarted = false; ScheduleManager.Stop(); ret = true; } return(ret); }
public bool Start(IPEndPoint localEndPoint) { var ret = false; if (_mIsStarted) { return(false); } _listenSocket = new Socket(localEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); try { _listenSocket.Bind(localEndPoint); _listenSocket.Listen(_mNumConnections); Program.Logger.InfoFormat($"Start listen socket {localEndPoint} success"); Program.OutputLog.LogFormat("Start listen socket {0} success", localEndPoint.ToString()); //for (int i = 0; i < 64; i++) //不能循环投递多次AcceptAsync,会造成只接收8000连接后不接收连接了 StartAccept(null); _mDaemonThread = new DaemonThread(this); _mIsStarted = true; ScheduleManager.Start(); ret = true; } catch (Exception ex) { Program.Logger.InfoFormat($"Start listen socket {localEndPoint} error", ex); Program.OutputLog.LogFormat("Start listen socket {0} error", localEndPoint.ToString()); } return(ret); }