Suppose there are server programs, ChatServer and client programs ChatClient. the client can send messages to the server. step 1. start listen on the server, 2. then the client connect.3. the client sends the message as long as the server starts listen, and the client also connects. after the connection is established. it is convenient to accept the sent information. You only need to use writer and reader to operate on the NetworkStream server ChatServer to create a WinForm page reference namespace: using System. net. sockets; using System. net; using System. IO; using System. threading; public class ChatServer {private int port = 54321; // port number private IPAddress ip = IPAddress. pa Rse ("10.20.30.40"); // ip address private TcpListener tcpListener = null; private TcpClient tcpClient = null; private NetworkStream networkStream = null; private BinaryReader reader; // private BinaryWriter writer; private string getInfo = string. empty; // start listening to private void btnStartListen_Click (object sender, EventArgs e) {tcpListener = new TcpListener (ip, port); tcpListener. start (); // Start listening to Thread acceptClientMs GThread = new Thread (AcceptClientMsg); // run a Thread to process the information sent from the client acceptClientMsgThread. start () ;}// process the information sent from the client private void AcceptClientMsg () {tcpClient = tcpListener. acceptTcpClient (); if (tcpClient! = Null) {networkStream = tcpClient. getStream (); reader = new BinaryReader (networkStream); while (true) {getInfo + = reader. readString (); // read the information sent from the client} // if you want to display the information, you can display the entire button (of course, the best way is to use some threads) // click the button to display txtShowClientMsg. text = getInfo; // if the server wants to send messages to the client, you can send the entire button. then add the following code // string sendMsg = txtSendMsge. text; // writer = new BinaryWriter (networkStream); // writer. write (sendMsg);} client ChatClient using System. net. sockets; using System. net; using System. IO; using System. threading; public class ChatClient {private int port = 54321; private IPAddress ip = IPAddress. parse ("10.20.30.40"); private TcpClient tcpClient = null; private NetworkStream networkStream = null; // private BinaryReader reader; private BinaryWriter writer; // connect serverprivate void btnStartConnect_Click (object sender, eventArgs e) {tcpClient = new TcpClient (); tcpClient. connect (ip, port); networkStream = tcpClient. getStream () ;}// send message private void btnStartConnect_Click (object sender, EventArgs e) {string sendMsg = txtSendMsg. text; writer = new BinaryWriter (networkStream); writer. write (sendMsg); // send information} // if you want to accept the message from the server. // reader = new BinaryReader (networkStream); // string getInfo = reader. readString ();}