During UDP packet sending and receiving, if the applications on the two hosts in the network need to communicate with each other, the first is to know the IP addresses of each other, and the second is to know the port that the program can listen. Because programs on the same host are differentiated by the network port number. UDP Socket usage process: 1. initialize the network library 2. Create a Socket of the SOCK_DGRAM type. 3. Bind a socket. 4. send and receive data. 5. Destroy the socket. 6. Release the network library. Principle of broadcast data packets: An address used to send data packets to All workstations in the network at the same time is called a broadcast address. In a network that uses the TCP/IP protocol, the IP address of the host identification segment whose host ID is full 1 is the broadcast address. If your IP address is 192.168.1.39 and the subnet mask is 255.255.255.0, the broadcast address is 192.168.1.255. If the IP address is 192.168.1.39 and the subnet mask is 255.255.255.255.192, the broadcast address is 192.168.1.63. If you only want to broadcast data in the current network, you only need to send data packets to the broadcast address. Such data packets can be routed and will be routed to all hosts in this segment through the router, this type of broadcast is also called direct broadcast. If you want to broadcast data throughout the network, you need to send data packets to 255.255.255.255. This type of data packet will not be routed. It can only reach all hosts in the physical network, this type of broadcast is called finite broadcast. The process of sending and receiving broadcast packets using UDP. Suppose we want to send a broadcast packet to the subnet 192.168.0.X with the subnet mask of 255.255.255.0. The procedure is as follows: 1. initialize the Winsock library. 2. Create a Socket of the SOCK_DIRAM type. 3. Set the attributes of the Socket to allow its broadcast. 4. Send the packet to 192.168.0.2555. Receive the broadcast packet that you broadcast. 6. Disable Socket7. release the network library. Note: 1. the receiver must know the broadcaster's slogan and then bind the port number to receive the message correctly. 2. the receiver's Socket does not need to be set to the broadcast attribute. 3. The bound IP address cannot use "127.0.0.1", but can use the real IP address or INADDR_ANY. Otherwise, the request fails to be received.