Beispiel #1
0
        private static void ReceiveMessage(Propagate propagate, string nick, byte[] buffer)
        {
            byte[] messageLengthBytes = new byte[2];
            Buffer.BlockCopy(buffer, 1, messageLengthBytes, 0, 2);
            int length = BitConverter.ToInt16(messageLengthBytes, 0); //the length of bytes of the message

            byte[] messageBytes = new byte[length];
            Buffer.BlockCopy(buffer, 3, messageBytes, 0, length);

            string message = nick + ":" + Encoding.UTF8.GetString(messageBytes);

            Console.WriteLine(message);
            propagate.PropagateMessages(message);
        }
Beispiel #2
0
        private static string ReceiveNick(Propagate propagate, string nick, byte[] buffer)
        {
            Byte[] messageLengthBytes = new byte[2];
            Buffer.BlockCopy(buffer, 1, messageLengthBytes, 0, 2);
            int length = BitConverter.ToInt16(messageLengthBytes, 0);

            byte[] messageBytes = new byte[length];
            Buffer.BlockCopy(buffer, 3, messageBytes, 0, length);
            string newNick = Encoding.UTF8.GetString(messageBytes);

            if (nick != String.Empty)
            {
                string message = "User changer its nick: " + nick + "  -------->  " + newNick;
                Console.WriteLine(message);
                propagate.PropagateMessages(message);
            }
            nick = newNick;
            return(nick);
        }