3. INTRODUCTION
TCP/IP-style networking is appropriate or most networking
needs.
It provides a serialized, predictable, reliable stream o packet data.
Datagrams are bundles of information passed between machines.
Java implements datagrams on top of the UDP protocol by using
two classes:
DatagramPacket (data container)
DatagramSocket (mechanism used)
4. DatagramSocket
The datagram socket class represents a connection-less socket for
sending or receiving datagram packets.
The datagram socket object is the data container used to send or
receive the datagram packets.
No guarantee of its content, arrival or arrival time
It defines four public constructors:
DatagramSocket() throws SocketException
-> Creates a DatagramSocket bound to any unused port.
5. Continue…
DatagramSocket(int port) throws SocketException
-> Creates a DatagramSocket bound to specified port.
DatagramSocket(int port, InetAddress ipAddress) throws
SocketException
-> Constructs a DatagramSocket bound to specified port &
InetAddress.
DatagramSocket(SocketAddress address) throws
SocketException
-> Creates a DatagramSocket bound to specified SocketAddress.
6. DatagramPacket
DatagramPacket is a message that can be sent or received
When multiple packets are sent, it may arrive in any order
Packet delivery is not guaranteed
Commonly used constructors:
DatagramPacket(byte data[], int size);
-> This constructor is used to receive the packets.
DatagramPacket(byte data[], int size, InetAddress ipAddress, int
port);
-> This constructor is used to send the packets.