Exemplo n.º 1
0
        private void SendButton_Click(object sender, EventArgs e)
        {
            MethodInvoker methodInvokerDelegate = delegate()
            {
                if (this.sendMessageTextBox.Text.Length >= 1)
                {
                    this.networkWatcher.Send(ProtocolCreator.Message(this.username, this.sendMessageTextBox.Text, this.sessionkey));
                    this.sendMessageTextBox.Text = string.Empty;

                    if (this.sendMessageTextBox.Focused == false)
                    {
                        this.sendMessageTextBox.Focus();
                    }
                }
            };

            if (this.InvokeRequired)
            {
                this.Invoke(methodInvokerDelegate);
            }
            else
            {
                methodInvokerDelegate();
            }
        }
Exemplo n.º 2
0
        public void EnterMessage()
        {
            Console.Clear();

            Console.Write(">> ");

            string message = Console.ReadLine();

            Protocol userMessage = ProtocolCreator.Message(this.username, message, this.sessionKey);

            NetworkManager.SendMessage(userMessage, outputWindowClient);
        }
Exemplo n.º 3
0
        public void ForwardMessagesToServer()
        {
            while (true)
            {
                string messageProtocol = NetworkManager.ReadMessage(inputWindowClient, 302);

                char[] mesageProtocolArray = messageProtocol.ToCharArray();

                if (messageProtocol[0] == 'C' && messageProtocol[1] == 'H' && messageProtocol[2] == 'A' && messageProtocol[3] == 'T' && messageProtocol[4] == 'M' && messageProtocol[5] == 'E')
                {
                    string messageString = string.Empty;

                    for (int i = 6; i < mesageProtocolArray.Length; i++)
                    {
                        messageString = messageString + mesageProtocolArray[i];
                    }

                    string[] messageProtocolContent = messageString.Split('-');

                    Protocol message = ProtocolCreator.Message(messageProtocolContent[0], messageProtocolContent[1], messageProtocolContent[2]);
                    NetworkManager.SendMessage(message, serverClient);
                }
            }
        }