Multicast the chatwaves
Use IP multicast along with custom stream classes to implement a cool, yet simple, peer-to-peer networked chat system
By Merlin Hughes, JavaWorld.com, 10/20/99
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Page 3 of 4
So, how do you know which group is yours? Well, that's a big picture issue. You can apply to the Internet Architecture and
Naming Authority (IANA), if you want; however, it's doubtful that IANA would assign you a group number just for a chat room.
More often, if the group will be restricted to just your organization, you can ask your system administrator to assign one
of the 16 million private-use group numbers (those beginning with 239).
To make administration easier, multicast supports a special time-to-live feature whereby you can limit how far messages will travel. You can restrict a chat group to just your department intranet,
for instance, or perhaps to your local Ethernet wire. There are two aspects to this. First, you must configure the routers
and tunnels of your network appropriately. Usually, this is performed by your system administrator. Second, you must choose
an appropriate time-to-live for the messages that you send; the value will depend on your local network configuration. A time-to-live
of 1 will restrict packets to your local Ethernet wire, while 63 typically restricts it to a single multicast island. You
can find more details in the Resources.
We now have an overall design for the chat system:
- Configure your network to be multicast-enabled. If you have multiple machines on a single hub or switch, they should be able
to communicate using multicast without any configuration.
- Choose a multicast group and a time-to-live that lets all the desired users connect to your chat session, but prevents messages
from travelling too far. For testing purposes, any multicast group in the 239.x.x.x range will do, as will a time-to-live
of 1.
- Join the multicast group so that you receive messages destined for it. Start a thread that listens for these messages and
display them in a text area.
- Open a text field for the user to enter messages. To transmit a message to the multicast group, simply drop it on the network
bound to the multicast address.
Data communications
IP multicast is built on top of the User Datagram Protocol (UDP). This type of network protocol is packet-based; you construct
a packet of information (up to 65,508 bytes long) and dispatch the packet (a datagram) into the network, bound for a particular destination (identified by an IP address and a port). The network will then try
to deliver the packet to the remote address. Upon successful delivery, the recipient will receive the exact payload that you
initially dispatched. However, the network sometimes loses the datagrams, sometimes duplicates them, and sometimes misorders
them (that is, packets may arrive in a different order than the one in which they were sent). Neither the sender nor the recipient
will receive notification of any such network errors. Rather, it is up to the application to identify and surmount such problems.
This is one of the complexities of datagram-based networking. The datagram protocols only guarantee that, if a packet is delivered,
it will be delivered intact.
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Resources
- Download the complete source for this article as a zip file
http://www.javaworld.com/javaworld/jw-10-1999/step/jw-10-step.zip
- Read all the other Java Step by Step columns
http://www.javaworld.com/topicalindex/jw-ti-step.html
- The IP Multicast Initiative is an international, multivendor forum accelerating the adoption of IP Multicast
http://www.ipmulticast.com/
- Stardust.com has lots of information about IP multicast, including references to related technology and products
http://www.stardust.com/multicast/
- The Reliable Multicast Protocol provides reliability on top of multicast
http://research.ivv.nasa.gov/RMP/
- WebCanal, a global information broadcast using multicast and Java, including LRMP (Lightweight Reliable Multicast Protocol)
as used in the JSDT (Java shared data toolkit)
http://webcanal.inria.fr/
- The MBone is currently the most widespread multicast backbone deployed on the Internet; instructions for how to get connected
are available here
http://www.mbone.com/
- MBone tools for Windows are listed here
http://www.softlab-nsk.com/Pro/Mbone.html
- The multimedia conferencing applications archive, including some Java multicast software, is here
http://www.video.ja.net/mice
- There have been many academic projects related to multicast; University College London has coordinated several. Among them
was the MICE project
http://www-mice.cs.ucl.ac.uk/multimedia/projects/mice/
- Then there was MERCI
http://www-mice.cs.ucl.ac.uk/multimedia/projects/merci/
- Then there was MECCANO
http://www-mice.cs.ucl.ac.uk/multimedia/projects/meccano/
- A rather old MBone FAQ is available hereftp://venera.isi.edu/mbone/faq.txt
- Information on IPv6 (Internet Protocol version 6) is available here
http://www.ipv6.org/
- "Building an Internet chat system," Merlin Hughes (JavaWorld, January 1997) -- an old article I wrote on implementing a unicast TCP/IP-based chat system
http://www.javaworld.com/javaworld/jw-01-1997/jw-01-chat.html
- Java Network Programming, Second Edition, by Merlin Hughes, Michael Shoffner, and Derek Hamner (Manning Publications, 1999) -- includes peer-to-peer and server-based
multicast chat applications
http://www1.fatbrain.com/asp/bookinfo/bookinfo.asp?theisbn=188477749X