Using Datagram Sockets
UDP datagram sockets are easy to use, after you understand how they work. A datagram socket has a specific port number assigned to it. You can specify the port number when you create the socket, or use port number 0 to allocate a random free port number. When you send a datagram packet, you can send it as a broadcast, meaning it goes to every host on the network, or you can send it to a specific host. The important thing to keep in mind is that you always send it to a port number, and not necessarily the same port number as your datagram socket.
Tip
When you send a datagram packet, you must always specify a host address. To broadcast a packet, set the host portion of the IP address to all 1s. For instance, if your network ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access