Exemplo n.º 1
0
        /**线程接收函数*/
        private void recPacketFun(object clientSocket)
        {
            if (clientSocket == null)
            {
                return;
            }
            Socket client = (Socket)clientSocket;

            if (!client.Connected)
            {
                return;
            }
            NetworkStream stream = new NetworkStream(client);
            BinaryReader  reader = new BinaryReader(stream);

            while (isClientRun)
            {
                //Console.WriteLine("recPacketThread***********");
                try
                {
                    ENUMS.MESSAGETYPE messageType = (ENUMS.MESSAGETYPE)reader.ReadByte();
                    CmdProcess.processCmd(this, reader, messageType);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("readThread:client is off line");
                    stopClient();/**clean socket*/
                    Console.WriteLine(ex.Message);
                    ErrorInfo.getErrorWriter().writeErrorMassageToFile(ex.Message + "\r\n" + ex.StackTrace + "\r\n");
                }
            }
        }