Пример #1
0
        private void onAccept(IAsyncResult result)
        {
            AsyncTcpServer server = result.AsyncState as AsyncTcpServer;
            TcpClient      client = null;

            try
            {
                client = server.m_listener.EndAcceptTcpClient(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + " >" + ex.StackTrace);
                if (client != null)
                {
                    client.Close();
                }
                server.StopServer();
                return;
            }

            try
            {
                server.m_listener.BeginAcceptTcpClient(new AsyncCallback(onAccept), server);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + " >" + ex.StackTrace);
                if (client != null)
                {
                    client.Close();
                }
                server.StopServer();
                return;
            }

            AsyncTcpSocket         socket            = new AsyncTcpSocket(client, server);
            INetworkSocketCallback socketCallbackObj = server.m_callBackObj.OnAccept(server, socket.GetIPInfo());

            if (socketCallbackObj == null)
            {
                socket.Disconnect();
            }
            else
            {
                socket.SetSocketCallback(socketCallbackObj);
                socket.Start();
                lock (server.m_listLock)
                {
                    server.m_socketList.Add(socket);
                }
            }
        }
Пример #2
0
 public AsyncTcpServer(AsyncTcpServer b)
     : base(b)
 {
     m_port      = b.m_port;
     m_serverOfs = b.m_serverOfs;
 }