Reputation: 742
I am developing an application in which broadcasting is essential. I have created two projects Client and server. I am able to send broadcast message but I am not receiving in server project. My code is as follows
Server:
private DatagramSocket _udpSocket = new DatagramSocket();
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
_udpSocket.MessageReceived += _udpSocket_MessageReceived;
await _udpSocket.BindServiceNameAsync("4777");
}
void _udpSocket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args)
{
}
Client
HostName h = new HostName("255.255.255.255");
IOutputStream outStream = await _socket.GetOutputStreamAsync(h, "4777");
DataWriter de = new DataWriter(outStream);
de.WriteByte(new byte());
await de.StoreAsync();
de.DetachBuffer();
But If on client side I replace 255.255.255.255 with local IPAddress, I can receive the message on the server.
What is the problem?
Upvotes: 3
Views: 2592
Reputation: 781
If I remember well my network 101 class, when you do a broadcast, the packet is not sent back to you, only to all other computers on the network (I might be wrong tough). Also, like TimVK said in his comment, you should try using your network's broadcast address instead of the general broadcast (for the network 192.168.0.0/24
(mask 255.255.255.0
) the broadcast would be 192.168.0.255
Upvotes: 2