The first phase of the project has been completed, and the requirements for the second phase have not yet been finalized.
In the previous article, we wrote the TCP protocol. Today we will write the UDP protocol. TCP has a connection protocol, so the client and the server need to establish a connection before sending and receiving messages; UDP is a non-connection protocol, so no connection is required before sending messages, you only need to send a message to the specified network endpoint, regardless of whether the endpoint exists or not, no matter whether the message arrives at the endpoint or not, no connection is required before receiving the message, you only need to receive it on the locally bound port. UDP does not have a clear client or server.
The program is based on the command line. After starting an instance, enter the local port number, remote IP address, and remote port number as prompted on the interface to enable communication between multiple instances.
After the program starts, first bind the local port according to the local port number entered, and then start a thread to receive data from the local port. Then, the interface prompts you to enter a message. After the input is complete, the message is sent to the remote IP address and the remote port number, enter a message again on the page ......
Run:
localPoint = IPEndPoint( socket = socket.Bind(localPoint);
Start the thread to receive data:
Show();
Data receipt details:
OnReceive( socket = obj (socket == ( receiveBuffer = [ EndPoint remotePoint = IPEndPoint(IPAddress.Any, receiveLength = socket.ReceiveFrom(receiveBuffer, }
Send cyclic execution data:
Show(, msg = EndPoint sendPoint = sendLength = } ();
I am a beginner. Thank you for your criticism!