Hello,
I'm having trouble with the JoinMulticastin gGroup 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 UDPMulticastLis tener
{
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(Grou pAddress, GroupPort);
try
{
listener.JoinMu lticastGroup(Gr oupAddress, 50);
listener.Connec t(groupEP);
while (!done)
{
Console.WriteLi ne("Waiting for broadcast");
byte[] bytes = listener.Receiv e(ref groupEP);
Console.WriteLi ne("Received broadcast from {0} :\n {1}\n",
groupEP.ToStrin g(),
Encoding.ASCII. GetString(bytes , 0, bytes.Length));
}
listener.Close( );
}
catch (SocketExceptio n e)
{
Console.WriteLi ne(e.toString() );
Console.ReadLin e();
}
}
public static int Main(String[] args)
{
StartListener() ;
return 0;
}
}
I'm having this message : System.Net.Sock ets.SocketExcep tion: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...
I'm having trouble with the JoinMulticastin gGroup 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 UDPMulticastLis tener
{
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(Grou pAddress, GroupPort);
try
{
listener.JoinMu lticastGroup(Gr oupAddress, 50);
listener.Connec t(groupEP);
while (!done)
{
Console.WriteLi ne("Waiting for broadcast");
byte[] bytes = listener.Receiv e(ref groupEP);
Console.WriteLi ne("Received broadcast from {0} :\n {1}\n",
groupEP.ToStrin g(),
Encoding.ASCII. GetString(bytes , 0, bytes.Length));
}
listener.Close( );
}
catch (SocketExceptio n e)
{
Console.WriteLi ne(e.toString() );
Console.ReadLin e();
}
}
public static int Main(String[] args)
{
StartListener() ;
return 0;
}
}
I'm having this message : System.Net.Sock ets.SocketExcep tion: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...
Comment