Example #1
0
        void disconect(Byte[] pac)
        {
            packetReader reader = new packetReader();

            users.Remove(reader.ReadUserID(pac));
            userClient.Remove(reader.ReadUserID(pac));
            NumberToAssine = reader.ReadUserID(pac);
        }
Example #2
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);
                }
            }
        }
Example #3
0
        void Send(Byte[] pac)
        {
            packetReader reader = new packetReader();

            foreach (KeyValuePair <int, TcpClient> kvp in userClient)
            {
                Console.WriteLine("entering foreach");
                if (kvp.Key != reader.ReadUserID(pac))
                {
                    Console.WriteLine("should be sending to other clients");
                    TcpClient     client = kvp.Value;
                    NetworkStream stream = client.GetStream();
                    stream.Write(pac, 0, pac.Length);
                }
            }
        }