Thursday, June 23, 2011

Multicast -- it's not really hard at all

So, I've been trying to learn some multicast programming. What I really want, of course, is to run a program on one computer in my local network (otherwise known as "home"), and then discover it on another computer.

So I figure multicast is the answer. And, in truth, it is! It's great! It's even simple! But every single silly blog post about it -- especially from the vendors -- makes it sound hard.

Here's the real deal on Multicast. It's just UDP. You send it to an IP address like 224.0.50.5. The exact values are pretty unimportant. And the port is just a port, like 9883. The server (listener) is just a hair more complex: bind to the same port, and set the "multicast join" socket option to the IP address.

Tada! Packets sent by the sender go to the listener. And you can reply from the server back to the sender by looking at the remote IP address.