www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - joining multicast groups with std.socket

--90e6ba1819a0ce030a04990cc72d
Content-Type: text/plain; charset=ISO-8859-1

I am trying to listen to a multicast group using the std.socket library. I
have looked at the documentation but I do not see a way to join a multicast
group. The code I have so far is pasted below. I am looking for
the IP_ADD_MEMBERSHIP socket option (along the lines of
http://www.cs.unc.edu/~jeffay/dirt/FAQ/comp249-001-F99/mcast-socket.html)
and can't find within the library.

Let's assume I am trying to listen to 225.0.0.37/12345

Can someone help me with a snippet on some d code that will do this?

I appreciate the help!

Peter



auto socket = new UdpSocket();
auto address = new InternetAddress(12345);
socket.bind(address);
auto multicastAddress = new InternetAddress("225.0.0.37");

/// The below naturally does not work and I can't seem to find

// How do I join the multicast address above?

byte[256] buffer;
int read = socket.receiveFrom(buffer);
printf("Received bytes %i", read);
return 0;

--90e6ba1819a0ce030a04990cc72d
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8"><s=
pan class=3D"Apple-style-span" style=3D"border-collapse: collapse; font-fam=
ily: arial, sans-serif; font-size: 13px; ">I am trying to listen to a multi=
cast group using the std.socket library. I have looked at the documentation=
 but I do not see a way to join a multicast group. The code I have so far i=
s pasted below. I am looking for the=A0IP_ADD_MEMBERSHIP socket option (alo=
ng the lines of=A0<a href=3D"http://www.cs.unc.edu/~jeffay/dirt/FAQ/comp249=
-001-F99/mcast-socket.html" target=3D"_blank" style=3D"color: rgb(51, 51, 2=
04); ">http://www.cs.unc.edu/~jeffay/dirt/FAQ/comp249-001-F99/mcast-socket.=
html</a>) and can&#39;t find within the library.<div>
<br></div><div>Let&#39;s assume I am trying to listen to=A0<a href=3D"http:=
//225.0.0.37/12345" target=3D"_blank" style=3D"color: rgb(51, 51, 204); ">2=
25.0.0.37/12345</a></div><div><br></div><div>Can someone help me with a sni=
ppet on some d code that will do this?=A0</div>
<div><br></div><div>I appreciate the help!</div><div><br></div><div>Peter</=
div><div><br></div><div><br></div><div><div><br></div><div><div>auto socket=
 =3D new UdpSocket();</div><div>auto address =3D new InternetAddress(12345)=
;</div>
<div>socket.bind(address);</div><div><span style=3D"white-space: pre-wrap; =
">	</span></div><div>auto multicastAddress =3D new InternetAddress(&quot;22=
5.0.0.37&quot;);</div><div><br></div><div>/// The below naturally does not =
work and I can&#39;t seem to find=A0</div>
<div><br></div><div>// How do I join the multicast address above?</div><div=
<br></div><div>byte[256] buffer;</div><div>int read =3D socket.receiveFrom=

iv> return 0;</div></div></div></span> --90e6ba1819a0ce030a04990cc72d--
Jan 04 2011