void disconect(Byte[] pac) { packetReader reader = new packetReader(); users.Remove(reader.ReadUserID(pac)); userClient.Remove(reader.ReadUserID(pac)); NumberToAssine = reader.ReadUserID(pac); }
//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); } } }
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); } } }