public void Message_Received_Event(MessageArgs message) { if (message.getMessage().Equals("quit")) { this.disconnect(); this.connected = false; } else printMessage(message); }
public void sendMessage(MessageArgs message) { bytes = new byte[1024]; data = null; bytes = Encoding.ASCII.GetBytes(message.getMessage()); stream.Write(bytes, 0, bytes.Length); if(Message_Sent != null) Message_Sent(message); }
private void printMessage(MessageArgs message) { Console.WriteLine(message.getName() + ": " + message.getMessage()); }
public void Message_Sent_Event(MessageArgs message) { printMessage(message); }
public void Client_Disc_Event(MessageArgs message) { printMessage(message); }
public void Client_Conn_Event(MessageArgs message) { printMessage(message); }
/// <summary> /// The primary function dealing with updating the client UI /// </summary> /// <param name="message"></param> private void Message_Sent_Event(MessageArgs message) { this.rtbChat.AppendText(message.getName() + ": " + message.getMessage() + Environment.NewLine); tbMessage.Text = placeholder; }
/// <summary> /// Events /// Message and client events handled here /// </summary> /// <param name="message"></param> private void Message_Received_Event(MessageArgs message) { if (message.getMessage().Equals("quit")) { this.connected = false; this.client.disconnect(); } ///Thread saftey dance else if(this.rtbChat.InvokeRequired) { ///Set the address of this function into the null delegate ts_ ///Then run ts_ (Recieved_Event) on the thread that owns ///The windows form handle of this.rtbChat (Invoke) this.rtbChat.Invoke(new ts_Message_Recieved_Event(this.Message_Received_Event), message); } ///When ts_ executes on the handle's native thread ///this else will run and the text will get outputted as normal else { this.rtbChat.AppendText(message.getName() + ": " + message.getMessage() + Environment.NewLine); this.rtbChat.ScrollToCaret(); if (!this.connected) this.tbMessage.Enabled = false; } }
/// <summary> /// The method called by public implementations like the chat app /// In order to send a message over TCP /// </summary> /// <param name="message"></param> public void sendMessage(MessageArgs message) { this.writeStream(message.getMessage()); if(Message_Sent != null) Message_Sent(message); }