Question

I am setting up a small local network with 3 laptops. My goal is to experiment with the UpNP protocol and have the laptops discover each other using UpNP. In order to do this, they need to be able to listen for notifications from each other. As per the protocol, these notifications are sent on multicast address 239.255.255.250:1900. However, I am having a problem setting the laptops up to listen on that address. I am starting just using 1 pc. My PC's IP address is 10.0.0.5.

However, when I try to set up a UdpClient to listen on 239.255.255.250:1900 I get an error saying: "The requested address is not valid in its context".

I have tried just setting it up using this:

IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900);
UdpClient client = new UdpClient(endpoint);
client.BeginReceive(MessageReceived, null);

I have also tried:

UdpClient client = new UdpClient(Port);
client.JoinMulticastGroup(IPAddress.Parse("239.255.255.250"));
client.BeginReceive(MessageReceived, null);

But I still get the same error: "The requested address is not valid in its context".

How do I correctly set up my UdpClient to listen on the multicast address 239.255.255.250:1900 ?

Thanks for your help!!!

Was it helpful?

Solution

Ok, after much searching and banging my head on my desk, I've got this thing working. I thought I had it working yesterday, but it only worked on Windows 7 and not on XP..

So, here it goes:

IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, Port);

UdpClient client = new UdpClient();
client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
client.Client.Bind(localEndPoint);
client.JoinMulticastGroup(IPAddress);
client.MulticastLoopback = true;

Client.BeginReceive(MessageReceived, null);

I sure wish this was documented a bit better, but I guess that's why we get the big bucks $$$.

Thanks StackOverflow for providing such an AWESOME knowledgebase from which to extract this stuff !!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top