我想使用Windows.Networking.Sockets.DatagramSocket在我的winRT应用程序中的端口50000上收听多播组239.192.168.22。这是我的代码片段:
class UdpSocketAnstraction : IDisposable
{
DatagramSocket socket;
public UdpSocketAnstraction()
{
this.socket = new DatagramSocket();
this.socket.MessageReceived += socket_MessageReceived;
}
public async Task Open()
{
await this.socket.BindServiceNameAsync("50000");
this.socket.JoinMulticastGroup(new HostName("239.192.168.22"));
}
}
JoinMulticastGroup抛出一个UnauthorizedAccessException而没有解释原因。
我不知道是否使用了这个套接字,或者我是否需要在我的窗口上放一些东西,或其他东西?
答案 0 :(得分:2)
在Package.appxmanifest文件中添加“Internet(客户端和服务器)”功能。双击它并转到声明选项卡。