0

I've a small software that works fine on windows 7. It makes some discovery using multicast on udp.

I started to make some tests on windows XP and I got some errors.

Socket sendSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
//ERROR HAPPEN ON THIS NEXT LINE
sendSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(m_multicastAddress, localAddress));
sendSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 255);
sendSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
sendSocket.MulticastLoopback = true;
sendSocket.Bind(new IPEndPoint(localAddress, m_port));
m_sendSockets.Add(localAddress, sendSocket);

The exception is:

System.Net.Sockets.SocketException was unhandled
  Message=An invalid argument was supplied
  Source=System
  ErrorCode=10022
  NativeErrorCode=10022
  StackTrace:
       at System.Net.Sockets.Socket.setMulticastOption(SocketOptionName optionName, MulticastOption MR)
       at System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Object optionValue)
       at [****]

I tested only this part of code in a 100 lines console program. It works fine on windows 7, but crash always on XP.

Do you have any idea about how to debug/resolve this?

J4N
  • 19,480
  • 39
  • 187
  • 340
  • Maybe it's just me.. but I can't seem to find XP as a supported platform for `MulticastOption`.. perhaps it isn't? – Simon Whitehead Mar 22 '13 at 12:48
  • possible duplicate of [C# SocketException with Multicast on XP](http://stackoverflow.com/questions/436659/c-sharp-socketexception-with-multicast-on-xp) – Ruud Aug 14 '13 at 06:22

1 Answers1

0

Sorry, I just found another answer where it has the exact exact same question:

C# SocketException with Multicast on XP

We have to call Bind before the join multicast socketOption

Community
  • 1
  • 1
J4N
  • 19,480
  • 39
  • 187
  • 340