开发者

ASP.NET Multicast UdpClient problems

开发者 https://www.devze.com 2022-12-14 09:12 出处:网络
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.

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 = ne开发者_运维知识库w 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.


client.ExclusiveAddressUse = false;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号