Title: Datagram Programming
Course: CPS 261: Advanced Java Concepts ~ DL & MM MASTER

Datagram programming

- java.net.DatagramSocket - member functions receive, send, and close
- java.net.DatagramPacket - member functions getAddress, getPort, and getData

Point to Point Quote Server

Source: QuoteServer.java
one-liners.txt
Source: QuoteClient.java

Multi-cast Quote Server

Source: MulticastServer.java
Source: MulticastClient.java
- You can use the MulticastSocket class derived from the DatagramSocket class. Our example uses a regular DatagramSocket with a group address.
- address = InetAddress.getByName("230.0.0.1")
Using an address like this on a datagram packet send results in a broadcast.
- A multicast group is specified by a class D IP address, those in the range 224.0.0.1 to 239.255.255.255, inclusive,
- Receiving a multicast packet requires the following call: socket.joinGroup(address) where address is obtained as shown above.
- socket.leaveGroup(address) to stop receiving multicast packets.

Last Modified: October 4, 2013 8:09 PM