Multicast giving invalid option specified

G

Guest

I am trying to send multicast messages using the following cod
Socket socket =new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp)
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, ttl)
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(message.Address.Address))

The code throws a runtime error on line
{"An invalid argument was supplied"
ErrorCode 10022
The same code works fine in .NET Frmwrk
 
A

Alex Feinman [MVP]

Couple of things:

1) A socket needs to be bound to an address before call to SetSocketOption
2) MulticastOption should have the Group property set:
MulticastOption opt = new MulticastOption("192.168.0.1");
opt.Group = IPAddress.Parse("239.255.255.254");
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership,
opt);

--
Alex Feinman
---
Visit http://www.opennetcf.org
Tejaswi said:
I am trying to send multicast messages using the following code
Socket socket =new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
socket.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.MulticastTimeToLive, ttl);
socket.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.AddMembership, new
MulticastOption(message.Address.Address));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top