Receiving broadcast messages
- by Prasad
Hi,
I'm trying to receive broadcast messages using C# code in an ISDN network with BRI interface at my end.
I see the packets sent to the broadcast ip address (239.255.255.255) on some ports using Comm View tool.
But when I try to listen to this IP address, it says the address is not in a valid context.
But when I send broadcast messages to 255.255.255.255 on a port, I can receive those messages with the below code..
What could be the problem with this ip address - 239.255.255.255 ?
The code I use to listen to broadcast messages is..
UdpClient udp = new UdpClient();
IPEndPoint receiveEndPoint = new IPEndPoint(IPAddress.Any, 8013);
// If I use IPAddress.Parse("239.255.255.255") to listen to,
// it says "the address is not in a valid // context."
udp.Client.Bind(receiveEndPoint);
udp.BeginReceive(_Callback, udp);
static private void _Callback(IAsyncResult iar)
{
try
{
UdpClient client = (UdpClient)iar.AsyncState;
client.BeginReceive(_Callback, client);
IPEndPoint ipRemote = new IPEndPoint(IPAddress.Any, 8013);
byte[] rgb = client.EndReceive(iar, ref ipRemote);
Console.WriteLine("Received {0} bytes: \"{1}\"",
rgb.Length.ToString(), Encoding.UTF8.GetString(rgb));
}
catch (ObjectDisposedException)
{
Console.WriteLine("closing listening socket");
}
catch (Exception exc)
{
Console.WriteLine("Listening socket error: \"" +
exc.Message + "\"");
}
}
There are packets sent to the broadcast ipaddress (239.255.255.255) which I can see in Commview tool, but can't receive them from the code...
Can anybody help me out please?
Thanking you in advance,
Prasad Kancharla.