Exemple #1
0
        public void TcpStart()
        {
            //启动TCP监听线程
            if (ServerMode)
            {
                //服务器模式
                tcpServer = new TcpServer(ServerIP, ServerPort); ;
                tcpThread = new Thread(new ThreadStart(tcpServer.StartListening));

                tcpServer.OnClientConnect += new DataEventHandler(tcpComm_OnClientConnect);
                tcpServer.OnClientDisconnect += new DataEventHandler(tcpComm_OnClientDisconnect);
                tcpServer.OnServerFull += new DataEventHandler(tcpComm_OnServerFull);
                tcpServer.OnClientDataAvailable += new DataEventHandler(tcpComm_OnClientDataAvailable);
                tcpThread.Start();

                while (!tcpThread.IsAlive) ;

            }
            else
            {
                //客户端模式
                tcpClient = new ClientSocket(ServerIP, ServerPort);
                tcpClient.OnSocketReceived += new SocketReceivedHandler(tcpClient_OnSocketReceived);
                tcpClient.OnSocketState += new SocketStateHandler(tcpClient_OnSocketState);
                tcpClient.Start();
            }
        }