ASP.NET Multicast UdpClient problems

家住魔仙堡 提交于 2019-12-24 19:29:27

问题


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
}

回答1:


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




回答2:


client.ExclusiveAddressUse = false;


来源:https://stackoverflow.com/questions/1941463/asp-net-multicast-udpclient-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!