K
Kevin S.
I'm trying to write code to receive broadcast UDP messages. These
broadcast messages are being sent from another computer on the local
network. My computer has more than one network connection.
This code works if I put the IP address of my own network connection
in the Bind() call.. If I try to use IPAddress.Any to bind, then
Available always returns 0, and if I call Receive anyway, it blocks
forever. Why won't IPAddress.Any work?
m_udpClient = new UdpClient();
m_udpClient.Client.SetSocketOption
(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
m_udpClient.EnableBroadcast = true;
m_udpClient.Client.Bind(new IPEndPoint(IPAddress.Any,
12012));
// m_udpClient.Client.Bind(new IPEndPoint(new IPAddress(new
byte[] { 192, 168, 0, 102 }), 12012));
(....)
while(whatever)
{
if(0!= m_udpClient.Available)
{
byte[] newBytes = m_udpClient.Receive(ref
m_udpIpEndpoint);
(... blah blah )
}
}
-Kevin
broadcast messages are being sent from another computer on the local
network. My computer has more than one network connection.
This code works if I put the IP address of my own network connection
in the Bind() call.. If I try to use IPAddress.Any to bind, then
Available always returns 0, and if I call Receive anyway, it blocks
forever. Why won't IPAddress.Any work?
m_udpClient = new UdpClient();
m_udpClient.Client.SetSocketOption
(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
m_udpClient.EnableBroadcast = true;
m_udpClient.Client.Bind(new IPEndPoint(IPAddress.Any,
12012));
// m_udpClient.Client.Bind(new IPEndPoint(new IPAddress(new
byte[] { 192, 168, 0, 102 }), 12012));
(....)
while(whatever)
{
if(0!= m_udpClient.Available)
{
byte[] newBytes = m_udpClient.Receive(ref
m_udpIpEndpoint);
(... blah blah )
}
}
-Kevin