On Tue, 18 Apr 2023 04:37:49 GMT, MrX wrote:

On Mon, 17 Apr 2023 07:39:11 GMT, Sönke Ludwig wrote:

On Sat, 08 Apr 2023 09:46:05 GMT, MrX wrote:

Hello,

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("239.1.1.234"); // 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. ntohl(biintfaddr.sockAddrInet4.S_addr)).

If you get some minimal example going, we should probably add it to the examples collection.

Thanks! Will give it a try, an let you know.

Actually I can not get this working..