On Sat, 08 Apr 2023 09:46:05 GMT, MrX wrote:
Does anyone have a vibe.d multicast sender and subscriber example that I could play with?
The documentation is not really helping.
Thanks in advance.
I don't have a full example to share, but the basic approach goes like this:
auto multicastaddr = resolveHost("220.127.116.11"); // freely chosen address within the multicast range auto intfaddr = resolveHost("127.0.0.1"); // replace by the appropriate interface address auto intfindex = 1; // replace by the appropriate interface index UDPConnection sock = listenUDP(bindaddr, UDPListenOptions.reusePort); sock.multicastLoopback = true; // just for supporting multicast within the same machine sock.addMembership(multicastaddr, intfindex); // send to all members sock.send(data, multicastaddr); // receive from any member, recording the origin address NetworkAddress srcaddr); sock.recv(buf, &srcaddr);
Since this is using IPv4, instead of passing the interface index, you could also pass the interface IP address as a 32-bit integer (i.e.
If you get some minimal example going, we should probably add it to the examples collection.