예제 #1
0
 private void Client_GotPrivateMessage(IrcMessage message)
 {
     // When the user receives a PRIVMSG command...
     BeginInvoke((Action)(() =>
     {
         // and if it is intended to be for this tab's target...
         if (message.args[0] == tabTarget)
         {
             // Display the message along with the sender.
             ChatDisplay.AppendText(message.sender + ": " + message.trail + "\r\n");
         }
     }));
 }
예제 #2
0
 private void chatBox_KeyUp(object sender, KeyEventArgs e)
 {
     // If the user pressed enter,
     if (e.KeyCode == Keys.Enter)
     {
         // Build a message object
         IrcMessage message = new IrcMessage(
             "PRIVMSG", new string[] { tabTarget }, chatBox.Text);               // PRIVMSG <nickname> <channel/user> :<message text>
         client.SendMessage(message);                                            // Send the message to the server,
         ChatDisplay.AppendText(client.Nickname + ": " + chatBox.Text + "\r\n"); // Display it on the client side,
         chatBox.Text = String.Empty;                                            // Then clear the chatbox.
     }
 }
예제 #3
0
 private void Client_OtherJoinedChannel(IrcMessage message)
 {
     // When another user joins the channel
     BeginInvoke((Action)(() =>
     {
         // and the message is for the tab's dedicated channel
         if (message.args[0] == tabTarget)
         {
             // Display a message
             ChatDisplay.AppendText(message.sender + " has joined " + tabTarget + "\r\n");
             // and add the user to the user list.
             userListBox.Items.Add(message.sender);
         }
     }));
 }
예제 #4
0
 private void Client_OtherPartedChannel(IrcMessage message)
 {
     // When another user parts from a channel
     BeginInvoke((Action)(() =>
     {
         // and if the message is for the tab's dedicated channel
         if (message.args[0] == tabTarget)
         {
             // Display a message
             ChatDisplay.AppendText(message.sender + " parted from " + tabTarget + "\r\n");
             // and remove the user from the list
             userListBox.Items.Remove(message.sender);
         }
     }));
 }
예제 #5
0
        //background work of sending message to client
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            if (client.Connected)
            {
                write.WriteLine(texttosend);
                this.ChatDisplay.Invoke(new MethodInvoker(delegate ()
                {
                    ChatDisplay.AppendText("Me: " + texttosend + "\n");
                }));
            }
            else
            {
                MessageBox.Show("Sending failed");
            }

            backgroundWorker2.CancelAsync();
        }
예제 #6
0
        //background work of receiving message from client
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            while (client.Connected)
            {
                try
                {
                    texttorecieve = read.ReadLine();
                    this.ChatDisplay.Invoke(new MethodInvoker(delegate ()
                    {
                        ChatDisplay.AppendText("Client: " + texttorecieve + "\n");
                    }));

                    texttorecieve = "";
                }
                catch (Exception er)
                {
                    MessageBox.Show(er.Message.ToString());
                }
            }
        }
        //client side connection with sever
        private void button1_Click(object sender, EventArgs e)
        {
            client = new TcpClient();
            IPEndPoint ipconnection = new IPEndPoint(IPAddress.Parse(textBox1.Text), int.Parse(textBox2.Text));

            try
            {
                client.Connect(ipconnection);

                if (client.Connected)
                {
                    ChatDisplay.AppendText("Connected to Server" + "\n");
                    read            = new StreamReader(client.GetStream());
                    write           = new StreamWriter(client.GetStream());
                    write.AutoFlush = true;
                    backgroundWorker1.RunWorkerAsync();
                    backgroundWorker2.WorkerSupportsCancellation = true;
                }
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message.ToString());
            }
        }
예제 #8
0
 public void DisplayText(string text)
 {
     ChatDisplay.AppendText(text + "\r\n");
 }