5.2. DatagramPacket Class

The DatagramPacket class represents a data packet intended for transmission using the User Datagram Protocol (see Figure 5-2). Packets are containers for a small sequence of bytes, and include addressing information such as an IP address and a port.

Figure 5-2. DatagramPacket representation of a UDP packet

The meaning of the data stored in a DatagramPacket is determined by its context. When a DatagramPacket has been read from a UDP socket, the IP address of the packet represents the address of the sender (likewise with the port number). However, when a DatagramPacket is used to send a UDP packet, the IP address stored ...

Get Java™ Network Programming and Distributed Computing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.