예제 #1
0
        // 先安一个连接设计
        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);
            }
        }
예제 #2
0
 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;
 }
예제 #3
0
 public ServerPeerCallback(int peerID, ITServerListener netDataHandler)
 {
     m_peerID         = peerID;
     m_netDataHandler = netDataHandler;
 }