public bool DetachClient(AsyncTcpSocket clientSocket)
 {
     lock (m_listLock)
     {
         return(m_socketList.Remove(clientSocket));
     }
 }
Exemple #2
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="packetType">packet type</param>
 /// <param name="packet">packet</param>
 /// <param name="offset">offset</param>
 /// <param name="size">size of packet in byte</param>
 /// <param name="iocpTcpClient">client socket</param>
 /// <param name="dataPacket">data packet for send</param>
 public PacketTransporter(PacketType packetType, Packet packet, int offset, int size, AsyncTcpSocket tcpClient, int dataType = -1, Packet dataPacket = null)
 {
     m_packetType  = packetType;
     m_packet      = packet;
     m_offset      = offset;
     m_size        = size;
     m_TcpClient   = tcpClient;
     m_dataPacket  = dataPacket;
     m_DataType    = dataType;
     m_callBackObj = tcpClient.m_callBackObj;
 }
        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);
                }
            }
        }