// 先安一个连接设计 public void StartListening(string ip, int port, ITServerListener serverListener) { if (m_isStartServr) { return; } m_isStartServr = true; m_serverListener = serverListener; IPAddress ipAddress = IPAddress.Parse(ip); IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port); m_listener = null; m_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { m_listener.Bind(localEndPoint); // Bind the socket to the local endpoint m_listener.Listen(m_maxConnectNum + 1); // Listen for incomming connections m_listener.BeginAccept(new AsyncCallback(this.OnConnectAccepted), m_listener); } catch (SocketException se) { WriteFiles.WritFile.Log(se); } catch (Exception ex) { WriteFiles.WritFile.Log(ex); } }
private AsynTcpServer() : base() { this.m_maxConnectNum = 10; this.m_peerMap = new Dictionary <int, ReliableOrderServerPeer>(); this.m_isStartServr = false; this.m_listener = null; this.m_serverListener = null; }
public ServerPeerCallback(int peerID, ITServerListener netDataHandler) { m_peerID = peerID; m_netDataHandler = netDataHandler; }