Пример #1
0
        public byte[] GetFile(ClassLibrary.Entites.File file, long partNumber)
        {
            PNRPManager manager = PeerServiceHost.PNRPManager;
            List <ClassLibrary.Entites.Peer> foundPeers = manager.ResolveByPeerName(file.PeerName);

            if (foundPeers.Count != 0)
            {
                ClassLibrary.Entites.Peer peer = foundPeers.FirstOrDefault();

                EndpointAddress endpointAddress = new EndpointAddress(string.Format("net.tcp://{0}:{1}/PeerToPeerClient.Services/PeerService",
                                                                                    peer.PeerHostName, ClassLibrary.Config.LocalPort));

                NetTcpBinding     tcpBinding = new NetTcpBinding(SecurityMode.None);
                PeerServiceClient client     = new PeerServiceClient(tcpBinding, endpointAddress);

                byte[] data = null;

                try
                {
                    data = client.TransferFile(file, partNumber);
                }
                catch
                {
                    throw new Exception("Unreachable host '" + file.PeerName);
                }

                return(data);
            }

            else
            {
                throw new Exception("Unable to resolve peer " + file.PeerName);
            }
        }
Пример #2
0
 public static void StartPeerServer() {
     pnrpManager = new PNRPManager(Config.LocalHostName, Config.LocalPort);
     PeerServiceHost host = new PeerServiceHost();
     host.DoHost(pnrpManager.Register());
 }