private void buttonSend_Click(object sender, EventArgs e) { if ((textBox_Input.Text.Length > 0) && (client != null)) { try { if (listBox_ClientList.SelectedIndex == 0) { PublicChatMsg publicMsg = new PublicChatMsg(); publicMsg.msg = textBox_Input.Text; MemoryStream outStream = publicMsg.WriteData(); client.Send(outStream.GetBuffer()); } else { PrivateChatMsg privateMsg = new PrivateChatMsg(); privateMsg.msg = textBox_Input.Text; privateMsg.destination = currentClientList[listBox_ClientList.SelectedIndex]; MemoryStream outStream = privateMsg.WriteData(); client.Send(outStream.GetBuffer()); } } catch (System.Exception) { } textBox_Input.Text = ""; } }
static void SendPrivateMessage(Socket s, String from, String msg) { PrivateChatMsg chatMsg = new PrivateChatMsg(); chatMsg.msg = msg; chatMsg.destination = from; MemoryStream outStream = chatMsg.WriteData(); try { s.Send(outStream.GetBuffer()); } catch (System.Exception) { } }
private void buttonSend_Click(object sender, EventArgs e) { if (client != null) { try { if (listBox_ClientList.SelectedIndex == 0) { PublicChatMsg publicMsg = new PublicChatMsg(); publicMsg.msg = textBox_Input.Text; MemoryStream outStream = publicMsg.WriteData(); client.Send(outStream.GetBuffer()); } // If == last item == "Game" Msg else if (listBox_ClientList.SelectedIndex == listBox_ClientList.Items.Count - 1) { GameMsg GameMessage = new GameMsg(); GameMessage.msg = textBox_Input.Text; GameMessage.destination = currentClientList[listBox_ClientList.SelectedIndex]; MemoryStream outStream = GameMessage.WriteData(); client.Send(outStream.GetBuffer()); } else { PrivateChatMsg privateMsg = new PrivateChatMsg(); privateMsg.msg = textBox_Input.Text; privateMsg.destination = currentClientList[listBox_ClientList.SelectedIndex]; MemoryStream outStream = privateMsg.WriteData(); client.Send(outStream.GetBuffer()); } } catch (System.Exception) { } textBox_Input.Text = ""; } }