我正在开发一个广播是必不可少的应用程序。我创建了两个项目客户端和服务器。我能够发送广播消息,但我没有在服务器项目中接收。我的代码如下
服务器:
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)
{
}
客户
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();
但是如果在客户端我用本地 IPAddress 替换 255.255.255.255,我可以在服务器上接收到消息。
问题是什么?