Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MultiCast Messages to multiple clients on the same machine

Im trying to write a server/service that broadcasts a message on the lan ever second or so, Kind of like a service discovery.

The message needs to be received by multiple client programs that could be on the same machine or different machines. But there could be more than one program on each machine running at the same time.

Im using delphi7, with indy 9.0.18

where im stuck is if i should be using UDP(TIdUDPClient/Server) or IP MultiCast (TIdIPMCastClient/Server) or if its even possible...

Ive managed to get it to work with IP Multi Cast with one client per machine, but even after many trys with different bindings.. max/min ports etc, i cant seem to find a solution.

like image 830
Christopher Chase Avatar asked Apr 09 '10 02:04

Christopher Chase


2 Answers

I think you're looking for the SO_REUSEADDR socket option. Setting that option on a socket allows multiple sockets to listen on the same port. For multicast Windows guarantees that the message will be delivered to all sockets (otherwise the message only goes to one socket, randomly).

You usually do this by calling setsockopt, but I'm not a Delphi developer so I'm not sure what your API looks like. This question seems to show an example of someone doing something similar in Delphi.

like image 154
shf301 Avatar answered Oct 12 '22 11:10

shf301


I have never done this, but it seems like "mailslots" is what you need. It will broadacast a message on the local network, and receive any replies from other workstations that know how to reply. This is how the popular "armadillo" license manager works (for making sure that registration keys aren't "over-subscribed"). My app (ClipMate) uses Armadillo to as a protection wrapper (shareware wrapper). When a registered user runs the app, it checks to see if that same key is in use by other machines on the same network. It basically says: "I'm using license 1234, how about you?" It waits for replies (i do this in a separate thread during startup so I don't block my startup). If other workstations report back that they're using the same key, I check the count against the number of seats contained in the license. I'm not entirely sure that it's as robust on Windows7....

like image 21
Chris Thornton Avatar answered Oct 12 '22 10:10

Chris Thornton