File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes Multicasting with Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Multicasting with Java?" Watch "Multicasting with Java?" New topic

Multicasting with Java?

Andrew Wisner

Joined: Aug 07, 2012
Posts: 4
I'm working on a Java server application that distributes a video feed to many Java clients. From my understanding, the best way to do this is with multicasting, and Java supports it. I understand the DatagramSocket/Packet objects, but I'm rather confused how exactly multicasting would work. My programming books/websites make it sound as though I simply pick a Class D IP address and bind both the server and the clients to it.

I have a tendency to over-complicate my algorithms, but this idea doesn't make any sense. It seems way to easy. How will the rest of the world know not to use the IP address I pick?

Can anyone suggest some (free) resources which might explain multicasting with Java better?

Andrew Wisner
Stephan van Hulst

Joined: Sep 20, 2010
Posts: 4200

Hi Andrew, welcome to CodeRanch!

Multicast is like radio. In radio, a transmitter broadcasts the show over a frequency, and radios have to tune in to that frequency. The same thing happens with multicast. The sender sends packets to a multicast address, and all receivers that have registered with that address will get the packet (not taking reliability into account, which is a problem with UDP obviously).

It really is that simple. Now, the thing that's preventing other applications from interfering, is the same reason that multicast may not be the solution to your problem: hardware support. Multicast is implemented by having routers duplicate packages if they are sent to a multicast address. However, most routers only support this within a LAN, and do not send multicast packages into the internet. So while multicast is excellent within a local network, you probably shouldn't rely on it if you want to distribute content over the internet.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Andrew Wisner

Joined: Aug 07, 2012
Posts: 4
Thank you so much for your quick reply! Ideally, I need the application to stream video to clients outside the LAN. I'll take a look into some other technologies then.
subject: Multicasting with Java?
jQuery in Action, 3rd edition