ASP.NET多播UdpClient问题 [英] ASP.NET Multicast UdpClient problems

查看:155
本文介绍了ASP.NET多播UdpClient问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的ASP.NET应用程序侦听多播UDP广播.不幸的是,由于权限/api问题,我似乎陷入了困境.

I'm trying to have my ASP.NET app listen for multicast UDP broadcasts. Unfortunately, I seem to be stuck in a bind due to permissions/api issues.

问题在于,由于ASP.NET应用程序会发生多次旋转,因此我需要允许应用程序的多个实例侦听同一IP/端口.为此,必须将SocketOptionName.ReuseAddress设置为true.问题在于,这需要我的ASP.NET应用程序不应该拥有的管理特权.

The problem is that I need to allow multiple instances of an application to listen to the same IP/Port since multiple spin-ups of the ASP.NET application will occur. To do this, the SocketOptionName.ReuseAddress must be set to true. The problem is that this requires administrative privileges that my ASP.NET app should not have.

代码如下:

public static void Listen(int port)
{
   var groupAddress = IPAddress.Parse("224.10.10.10");
   var endPoint = new IPEndPoint(groupAddress, port);
   var client = new UdpClient();

   client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
   client.Client.Bind(new IPEndpoint(IPAddress.Any, port)); // Error thrown here       
   client.JoinMulticastGroup(groupAddress);       

   var udpState = new UdpState() { Client = client, EndPoint = endPoint };
   client.BeginReceive(OnMessageReceived, udpState); // OnMessageReceived code omitted
}

推荐答案

不幸的是,如果没有管理权限,这似乎是不可能的.如果有人有其他想法,我很想听听他们的想法.

Unfortunately, it seems as though this isn't possible without administrative rights. If anyone has any other ideas, I'd love to hear them.

这篇关于ASP.NET多播UdpClient问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆