471,336 Members | 1,323 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,336 software developers and data experts.

JoinMulticastingGroup & Compact Framework

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...
Jul 21 '05 #1
1 1905
I think you may need to remove Connect command. See
http://groups.google.co.uk/groups?hl...3DN%26tab%3Dwg
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

"Ben" wrote:
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...

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Asad Khan | last post: by
14 posts views Thread by Ioannis Vranos | last post: by
reply views Thread by carmen | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.