以下代码适用于管理员帐户,但对于非管理员帐户,它会打印两次成功然后抛出 System.Net.Sockets.SocketException (0x80004005):尝试以其禁止的方式访问套接字访问权限。任何人都知道这是为什么?
仅供引用,这里的实际用例是多个应用程序使用相同的 PGM 地址和套接字。推送(通过多播)实时更新。这不是由我们自己的库引起的概念证明。
class Program {
static void Main(string[] args) {
IPAddress ipAddr = IPAddress.Parse("239.0.0.2");
IPEndPoint end = new IPEndPoint(ipAddr, 40002);
Socket[] _sockets = new[] {
new Socket(AddressFamily.InterNetwork, SocketType.Rdm, (ProtocolType)113 ),
new Socket(AddressFamily.InterNetwork, SocketType.Rdm, (ProtocolType)113 ),
new Socket(AddressFamily.InterNetwork, SocketType.Rdm, (ProtocolType)113 )
};
foreach (var socket in _sockets)
{
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
socket.Bind(end);
Console.WriteLine("Success");
}
Console.ReadLine();
}
最佳答案
好吧,我终于从微软那里得到了关于这个的消息,而且没有解决方法。
I was able to find the line where your request was denied.
[0] 22E8.1554::08/15/2012-10:05:19.015 [sys] address_c491 PgmCreateAddress() - PgmCreateAddress: ERROR -- Non-admin user trying to open 2+1 handle for IP:Port=
With a little code review, I was able to verify that only three principals are granted access, and they are Administrators, LocalService and NetworkService. Apart from being a member of Administrators, there is no workaround.
I know this wasn’t the answer you wanted to hear, but at least now you have a confirmed answer.
关于c# - 在非管理员帐户上使用多个 PGM 监听套接字获取访问异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11747545/