Search code examples
delphidelphi-7indymulticastindy-9

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.


Solution

  • 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.