JoinMulticastingGroup & Compact Framework

B

Ben

Hello,

I'm having trouble with the JoinMulticastingGroup function with C#
..NET and the Compact Framework. My console application on my PocketPC
has to listen for any datagrams coming from the network, by UDP
protocol. Here is a sample of my code :

public class UDPMulticastListener
{
private static readonly IPAddress GroupAddress =
IPAddress.Parse("127.0.0.1");
private const int GroupPort = 9000;

private static void StartListener()
{
bool done = false;

UdpClient listener = new UdpClient();
IPEndPoint groupEP = new IPEndPoint(GroupAddress, GroupPort);

try
{
listener.JoinMulticastGroup(GroupAddress, 50);
listener.Connect(groupEP);

while (!done)
{
Console.WriteLine("Waiting for broadcast");
byte[] bytes = listener.Receive(ref groupEP);

Console.WriteLine("Received broadcast from {0} :\n {1}\n",
groupEP.ToString(),
Encoding.ASCII.GetString(bytes, 0, bytes.Length));
}

listener.Close();

}
catch (SocketException e)
{
Console.WriteLine(e.toString());
Console.ReadLine();
}
}

public static int Main(String[] args)
{
StartListener();

return 0;
}
}

I'm having this message : System.Net.Sockets.SocketException:An
invalid argument was supplied

I've put the address "127.0.0.1" because I want the application to
catch any datagram comming from the network, so it has to work
localhost. For what I've read from the msdn, the range has to be
between 224.0.0.0 and 239.255.255.255. But if I specify and address in
this range, I have the same message.

Instead of posting "e.toString()", if I post "e.ErrorCode()", I
receive the error code 10022, but I have absolutely no idea what it
means, and I didn't find any much help on that matter on the msdn.

Thanks in advance for the help you could give me...
 
G

Guest

I think you may need to remove Connect command. See
http://groups.google.co.uk/groups?h...=udp%20multicast%20c%23&hl=en&lr=&sa=N&tab=wg
for a useful discussion on IP multicasting.

Couple of other minor points. I would suggest creating the UdpCLient object
in a using block, as if your code encounters an exception, the UdpClient
object will not be disposed. Also, cannot see where done is set to true to
allow loop to break.

Of course, this could just be demo code, in whichc ase ignore me!

HTH
Dan
 

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

Similar Threads

UdpClient 2
Problem on MSDN 2
Asynchronous Sockets Client - Returning status 3
Working with binary data? 10
Asynchronous image transfer over TCP/IP socket 0
UDP with VB.NET 2
Async UDP socket 1
Using an API 2

Top