TCP client /server connection

Client:

using (TcpClientConnection client = new TcpClientConnection()) {
    client.NetworkStream = new NetworkStream();
 
    client.TimeOut = 60000;
    client.Open(HostResolver.GetIPAddress("127.0.0.1"), 2110);
    MessageBox.Show("Client connected");
 
    using (StringStream data = new StringStream("Data to be sent")) {
        client.WriteData(data);
        data.SetLength(0);
        client.IsReadUntilClose = true;
        client.ReadData(data);
 
        MessageBox.Show(data.DataString);
    }
 
    client.Close(true);
    MessageBox.Show("Client disconnected");
}

Server:

using (TcpServerConnection server = new TcpServerConnection()) {
    server.NetworkStream = new NetworkStream();
 
    server.TimeOut = 60000;
    server.BatchSize = 8192;
    server.Open(2110);
    server.Accept();
    textBox1.Text += "connected\r\n";
 
    using (StringStream data = new StringStream()) {
        server.ReadData(data);
        data.Position = 0;
        server.WriteData(data);
    }
 
    textBox1.Text += "read done\r\n";
 
    server.Close(false);
    textBox1.Text += "closed\r\n";
}
 
Have questions?
Join us Facebook   YouTube   Twitter   Telegram   Newsletter
 
Kind regards
Clever Components team
www.CleverComponents.com

Add Feedback