Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. namespace client1
  2. {
  3. public partial class Form1 : Form
  4. {
  5.  
  6. const int PORT_NO = 8000;
  7. const string SERVER_IP = "127.0.0.1";
  8.  
  9. TcpClient client;
  10. NetworkStream nwStream;
  11. TcpListener listener;
  12.  
  13. public Form1()
  14. {
  15. InitializeComponent();
  16.  
  17. }
  18.  
  19. private void button1_Click(object sender, EventArgs e)
  20. {
  21. string textToSend = textBox1.Text;
  22. string userToSend = textBox2.Text;
  23. string result = userToSend + ":" + textToSend;
  24. listBox1.Items.Add(result);
  25.  
  26. string frame = "*" + userToSend + "*" + textToSend + "*";
  27. client = new TcpClient(SERVER_IP, PORT_NO);
  28. nwStream = client.GetStream();
  29. byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes(frame);
  30.  
  31. nwStream.Write(bytesToSend, 0, bytesToSend.Length);
  32.  
  33. nwStream.Flush();
  34.  
  35. }
  36.  
  37. private void button2_Click(object sender, EventArgs e)
  38. {
  39. nwStream.Close();
  40. client.Close();
  41. }
  42.  
  43. private void Form1_Load(object sender, EventArgs e)
  44. {
  45.  
  46. }
  47.  
  48.  
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement