Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace client1
- {
- public partial class Form1 : Form
- {
- const int PORT_NO = 8000;
- const string SERVER_IP = "127.0.0.1";
- TcpClient client;
- NetworkStream nwStream;
- TcpListener listener;
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string textToSend = textBox1.Text;
- string userToSend = textBox2.Text;
- string result = userToSend + ":" + textToSend;
- listBox1.Items.Add(result);
- string frame = "*" + userToSend + "*" + textToSend + "*";
- client = new TcpClient(SERVER_IP, PORT_NO);
- nwStream = client.GetStream();
- byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes(frame);
- nwStream.Write(bytesToSend, 0, bytesToSend.Length);
- nwStream.Flush();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- nwStream.Close();
- client.Close();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement