Multicast giving invalid option specified

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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));
 
Back
Top