Ejemplo n.º 1
0
 private void OnAccept(IAsyncResult result)
 {
     if (m_Server == null)
     {
         return;
     }
     try
     {
         m_Server.SocketLog("OnAccept:new connect");
         var server = result.AsyncState as Socket;
         var socket = server.EndAccept(result);
         var index  = NewIndex();
         if (index < 0)
         {
             socket.Close();
             m_Server.SocketLogError("XSocketServer OnAccept ERROR: connect max.");
         }
         else
         {
             var conn = m_Clients[index];
             conn.Init(socket);
             OnClientConnectCallback?.Invoke(conn);
             conn.BeginReceive();
         }
         m_Server.BeginAccept(OnAccept);
     }
     catch (Exception e)
     {
         m_Server.SocketLogError("XSocketServer OnAccept ERROR:" + e.Message);
     }
 }
Ejemplo n.º 2
0
 public void Start()
 {
     m_Server      = new XSocket();
     m_Server.Name = "Server";
     m_Server.Listen(m_IP, m_Port, m_MaxConnection, OnAccept);
     m_Server.SocketLog("XSocketServer Start");
 }