//监听 public void Listen(IPEndPoint endPoint) { if (this.OnAccepted == null) { throw new Exception("need set event OnAccepted"); } if (this.OnClosed == null) { throw new Exception("need set event OnClosed"); } if (this.OnRecv == null) { throw new Exception("need set event OnRecv"); } logger.Warn("Module listen==" + endPoint.ToString()); if (this.socketListen != null) { throw new Exception("already in listen"); } socketListen = new Socket(SocketType.Stream, ProtocolType.Tcp); if (endPoint.AddressFamily == AddressFamily.InterNetworkV6) { socketListen.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false); socketListen.Bind(new IPEndPoint(IPAddress.IPv6Any, endPoint.Port)); } else { socketListen.Bind(endPoint); } socketListen.Listen(10000); StartAccept(null); logger.Info("==Module listen"); }