RejectedSoftware Forums

Sign up

Multicast send/receiver example

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.

Re: Multicast send/receiver example

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.

Re: Multicast send/receiver example

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.

Re: Multicast send/receiver example

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

Re: Multicast send/receiver example

Am 18.04.2023 um 21:26 schrieb MrX:

Actually I can not get this working..

Which OS are you running? I can try to get something running when I get
some time.

Re: Multicast send/receiver example

On Wed, 19 Apr 2023 09:34:18 +0200, Sönke Ludwig wrote:

Am 18.04.2023 um 21:26 schrieb MrX:

Actually I can not get this working..

Which OS are you running? I can try to get something running when I get
some time.

I am on GNU/Linux.
Thanks that would help a lot.

Re: Multicast send/receiver example

On Wed, 19 Apr 2023 09:16:44 GMT, MrX wrote:

On Wed, 19 Apr 2023 09:34:18 +0200, Sönke Ludwig wrote:

Am 18.04.2023 um 21:26 schrieb MrX:

Actually I can not get this working..

Which OS are you running? I can try to get something running when I get
some time.

I am on GNU/Linux.
Thanks that would help a lot.

I would still love to have an working example if possible.