为什么我不能在Windows 8.1中注册我的P2P应用程序

时间:2018-10-30 20:40:50

标签: c# p2p

我正在尝试学习有关P2P的一些知识。这就是为什么我试图在装有Windows 8.1操作系统的计算机上运行以下代码示例:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.PeerToPeer;
using System.Net.PeerToPeer.Collaboration;

namespace PeerChat
{
    public class PeerChatApplication
    {
        private static PeerApplication PeerChatPeerApplication;
        private static Guid PeerChatAppId = new Guid("2B6FFB9A-8BCD-4B2E-9958-090E2E6FB5D7");
        private static string PeerChatDescription = "A sample peer networking application.";

        static PeerChatApplication()
        {
            PeerChatPeerApplication = new PeerApplication(PeerChatAppId, 
                                                          PeerChatDescription, 
                                                          null,
                                                          System.Windows.Forms.Application.ExecutablePath, 
                                                          null,
                                                          PeerScope.All);
        }

        public static void SignIn()
        {
            PeerCollaboration.SignIn(PeerScope.All);
        }

        public static void Register()
        {
            PeerApplicationCollection peerAppsColl = PeerCollaboration.GetLocalRegisteredApplications(PeerApplicationRegistrationType.AllUsers);

            IEnumerable<PeerApplication> findPeerApp = from peerApp in PeerCollaboration.GetLocalRegisteredApplications(PeerApplicationRegistrationType.AllUsers)
                                                       where peerApp.Id == PeerChatAppId
                                                       select peerApp;

            if (findPeerApp.Count<PeerApplication>() != 0) 
                PeerCollaboration.UnregisterApplication(PeerChatPeerApplication, PeerApplicationRegistrationType.AllUsers);

            PeerCollaboration.RegisterApplication(PeerChatPeerApplication, PeerApplicationRegistrationType.AllUsers);
        }

        public static void UnRegister()
        {
            PeerCollaboration.UnregisterApplication(PeerChatPeerApplication, PeerApplicationRegistrationType.AllUsers);
        }
    }
}

首先,您需要登录并随后注册。在Windows 7中(使用管理员的登录名)可以很好地工作。

在Windows 8.1中,我遇到以下异常:“ Windows Peer-to-Peer基础结构未获得在此平台上运行的许可”。

这是否意味着Windows 8.1操作系统不支持P2P?

0 个答案:

没有答案