예제 #1
0
 public static void Init(DP_Msg data)
 {
     if (Program.m_MainLoop.m_UseTcp)
     {
         TestTcp.Init(data);
     }
     else
     {
         TestUdp.Init();
     }
 }
예제 #2
0
    /// <summary>
    /// 监听客户端连接
    /// </summary>
    private static void ListenClientConnect()
    {
        while (m_ListenClientConnectThread.IsAlive)
        {
            Socket clientSocket = serverSocket.Accept();
            Log.print("有客户端{0}连接进来了", clientSocket.RemoteEndPoint.ToString());
            //初始化新建立连接的数据
            DP_Msg clientData = new DP_Msg();
            clientData.clientSocket   = clientSocket;
            clientData.m_LastConnTime = Environment.TickCount;
            Log.print("连接的TickCount:" + Environment.TickCount);
            PacketRegister.Init(clientData);

            Thread m_ReceiveMessageThread = new Thread(ReceiveMessage);
            Thread m_SendMessageThread    = new Thread(SendMessage);
            Thread m_ProcessMessageThread = new Thread(ProecssMessage);
            clientData.m_ProcessMessageThread = m_ProcessMessageThread;
            clientData.m_SendMessageThread    = m_SendMessageThread;
            clientData.m_ReceiveMessageThread = m_ReceiveMessageThread;

            Thread m_TestConnectionThread = new Thread(TestConnection);

            m_TestConnectionThread.Start(clientData);
            m_SendMessageThread.Start(clientData);
            m_ProcessMessageThread.Start(clientData);
            m_ReceiveMessageThread.Start(clientData);

            //向客户端发送一个HelloWorld
            if (Program.m_MainLoop.m_UseTcp)
            {
                TestTcp.SendMsg(clientData);
            }
            else
            {
                TestUdp.SendMsg(clientData);
            }
        }
    }