2

I'm trying to send out a multicast packet then receive the response that comes back (there should only be one response.) I can send the packet, and wireshark shows the reply but my program never receives it. I've tried a few different things but this is the current state of my non-functioning code.

IPEndPoint epReceive = new IPEndPoint(IPAddress.Any, 5355);
IPEndPoint epSend = new IPEndPoint(IPAddress.Parse("224.0.0.252"), 5355);

UdpClient sendClient = new UdpClient();
sendClient.ExclusiveAddressUse = false; 
sendClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
sendClient.Client.Bind(epReceive);
sendClient.Send(packet, packetLength, epSend);

byte[] buffer = sendClient.Receive(ref epReceive);


sendClient.Close();

This code just hangs on the sendClient.Receive() line. I realise this code is currently blocking and could/should be threaded, but for the purposes it's being used for it's not a concern.

Sam
  • 374
  • 1
  • 3
  • 14
  • Receiving a multicast message is not that simple. see http://stackoverflow.com/q/767215/1212012 – Mathieu Aug 23 '16 at 08:36
  • Why you are set sendClient.ExclusiveAddressUse = false? – Alexander Kiselev Aug 23 '16 at 08:36
  • Destination end-point must be IPAddress.Broadcast: IPEndPoint epSend = new IPEndPoint(IPAddress.Broadcast, 5355); – Alexander Kiselev Aug 23 '16 at 08:45
  • From my understanding the response is not a multicast. It should be a direct reply to the sending IP. Also the sendClient.ExcluseiveAddressUse = false was left over code from when I was trying to do the same thing using two udp clients I believe. I've removed it but it makes no difference. Also, I believe the sending IP is correct as it is a multicast, not a broadcast message. As stated, the packet goes out and is received by the other end fine, I simply can't read the response in the app. – Sam Aug 23 '16 at 08:45

0 Answers0