ASP.NET 多播 UdpClient 问题
我正在尝试让我的 ASP.NET 应用程序侦听多播 UDP 广播。不幸的是,由于权限/api 问题,我似乎陷入了困境。
问题是我需要允许应用程序的多个实例侦听相同的 IP/端口,因为 ASP.NET 应用程序将发生多次旋转。为此,SocketOptionName.ReuseAddress 必须设置为 true。问题是这需要我的 ASP.NET 应用程序不应该拥有的管理权限。
这是代码:
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
}
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.
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.
Here's the code:
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,如果没有管理权限,这似乎是不可能的。如果有人有任何其他想法,我很想听听。
Unfortunately, it seems as though this isn't possible without administrative rights. If anyone has any other ideas, I'd love to hear them.