1. First, add two windows form projects, one as the server and the other as the Client.
2. Then add the server code and namespace. The TextBox Control is added to the interface.
System.Net.Sockets;
3. Add code using the FormLoad Method
Form1_Load(= IPEndPoint(IPAddress.Parse(), ); Socket socket = Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Bind(epServer); socket.Listen(); socket.BeginAccept( AsyncCallback(RecVing), socket); }
4. Add the callback method code.
cmdstr = ==[] bytes = [ i == Encoding.UTF8.GetString(bytes,
5. Add the showstrs method,
Define private delegate void shixudong_invoke (string invokefun );
showstrs( (recv_strs.Length != (= .Invoke(invoke, (=
6. By now, the server has been added
7. client code. Add a namespace and add a button event on the interface, just like the server.
button1_Click(= IPEndPoint(IPAddress.Parse(), ); Socket socket = AsyncCallback(Sending), socket); }
8. Add the callback method. The Code is as follows:
=[] msgBuff =, ,
9. The client code has been completed so far. Start the server before debugging.
10. Run the following command. before clicking the button, enter shixudong in the text box.
11. click the button as follows:
Test successful, if you have any questions, please contact me shixudong3@yeah.net, hope you can help more!