Example #1
0
        private void buttonJoin_Click(object sender, EventArgs e)
        {
            var name = this.textBoxName.Text;

            if (name == "")
            {
                this.errorProvider.SetError(this.textBoxName, "Please enter your name.");
            }
            else
            {
                SimpleChatServer.IncomingMessage += SimpleChatServer_IncomingMessage;
                try
                {
                    SimpleChatServer.Join(name);
                    this.joined = true;

                    UpdateUIState();

                    this.textBoxMessage.Focus();
                    this.errorProvider.SetError(this.textBoxName, null);

                    // when joining from a browser that doesn't support WebSocket, enable the update timer.
                    if (!Application.IsWebSocket)
                    {
                        this.updateTimer.Start();
                    }
                }
                catch
                {
                    SimpleChatServer.IncomingMessage -= this.SimpleChatServer_IncomingMessage;
                    throw;
                }
            }
        }
Example #2
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            var text = this.textBoxMessage.Text;

            if (text == "")
            {
                this.errorProvider.SetError(this.textBoxMessage, "Please enter a message.");
            }
            else
            {
                this.textBoxMessage.Text = "";
                var name = this.textBoxName.Text;
                SimpleChatServer.SendMessage(name, text);
                this.errorProvider.SetError(this.textBoxMessage, null);
            }
        }
Example #3
0
        private void buttonLeave_Click(object sender, EventArgs e)
        {
            var name = this.textBoxName.Text;

            SimpleChatServer.Leave(name);
            SimpleChatServer.IncomingMessage -= this.SimpleChatServer_IncomingMessage;

            this.joined = false;
            UpdateUIState();

            // when leaving from a browser that doesn't support WebSocket, stop the update timer.
            if (this.updateTimer.Enabled)
            {
                this.updateTimer.Stop();
            }
        }