示例#1
0
        //this is the infint lissen loop
        void receveMessages(TcpClient client)
        {
            NetworkStream stream = client.GetStream();
            packetReader  reader = new packetReader();

            while (true)
            {
                Console.WriteLine(" in the receve loop");
                Byte[] buffer = new Byte[256];
                try
                {
                    stream.Read(buffer, 0, buffer.Length);
                    Console.WriteLine("the user id is " + reader.ReadUserID(buffer));
                    comandInterpriter(reader.readCMD(buffer), buffer, client);
                    Console.WriteLine(reader.ReadMessage(buffer, reader.readHeader(buffer)));
                    if (reader.readCMD(buffer) == 3)
                    {
                        Thread.CurrentThread.Join();
                    }
                } catch (Exception e)
                {
                    Console.WriteLine("this is throwing an exceion " + e);
                }
            }
        }
示例#2
0
        void handdleConections(IAsyncResult result)
        {
            TcpListener  server = (TcpListener)result.AsyncState;
            TcpClient    client = server.EndAcceptTcpClient(result);
            packetReader reader = new packetReader();

            Byte[]    data     = new Byte[256];
            IPAddress clinetIp = IPAddress.Parse(((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString());

            Console.WriteLine("incomint conection");
            NetworkStream stream = client.GetStream();

            stream.Read(data, 0, data.Length);
            if (reader.readVerification(data))
            {
                comandInterpriter(reader.readCMD(data), data, client);
            }
            Thread receveMSG = new Thread(() => receveMessages(client));

            receveMSG.Start();
        }