.NET Framework Developer Center >
.NET Development Forums
>
.NET Framework Networking and Communication
>
P2P on XP
P2P on XP
- Hi,
I've been trying to create a small P2P application for testing purposes using WCF (System.Net.PeerToPeer namespace) but I'm having difficulties getting some simple code to work on XP.
This is my code to register a new peer name and then resolve any peers of a certain name that it can find.
Code Snippetvar peerName = new PeerName("Test Peer", PeerNameType.Secured);
_peerNameReg = new PeerNameRegistration(peerName, 80);
_peerNameReg.Comment = "Test comment.";
_peerNameReg.Start();
testListBox.Items.Add(_peerNameReg.PeerName.ToString());
var peerNameResolver = new PeerNameResolver();
var result = peerNameResolver.Resolve(new PeerName("Test Peer", PeerNameType.Secured));
foreach (var item in result)
testListBox.Items.Add(item.PeerName.ToString());
This code works fine on Vista - the peer name is registered and PNRP resolution succeeds (though result contains zero records). On XP (SP3 with advanced networking installed) peer name registration succeeds but then I get the following exception on the line that calls peerNameResolver.Resolve.
System.Net.PeerToPeer.PeerToPeerException: Could not start name resolution. ---> System.Runtime.InteropServices.COMException (0x80631001): Exception from HRESULT: 0x80631001
--- End of inner exception stack trace ---
at System.Net.PeerToPeer.PeerNameResolver.Resolve(PeerName peerName, Cloud cloud, Int32 maxRecords)
at System.Net.PeerToPeer.PeerNameResolver.Resolve(PeerName peerName, Cloud cloud)
at P2pNetMessenger.MainWindow.OnInitialized(EventArgs e) in C:\Users\Alex\Documents\Visual Studio 2008\Projects\P2P Net Messenger\P2P Net Messenger\MainWindow.xaml.cs:line 40
at System.Windows.FrameworkElement.TryFireInitialized()
at System.Windows.FrameworkElement.EndInit()
at System.Windows.Markup.BamlRecordReader.ElementEndInit(Object& element)
The HResult suggests that "An attempt has been made to access a cloud that does not exist." (see this), but even when I explicitly set the Cloud in code I receive the same error.
Is there perhaps something wrong with my XP configuration, or maybe there is a way to fix this issue in code?
Thanks in advance...
All Replies
- Hi,I have a similar problem. This is my "server-side" code:[CODE]using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net.PeerToPeer;using System.Net;namespace TestPeerToPeerServer{class Program{static void Main(string[] args){PeerName peerName = new PeerName("TSFPeerServer", PeerNameType.Unsecured);PeerNameRegistration pnReg = new PeerNameRegistration(peerName, 8889, Cloud.AllLinkLocal);pnReg.Comment = "Server attualmente attivo";pnReg.Data = System.Text.Encoding.UTF8.GetBytes("Dati associati al peer");try{pnReg.Start();System.Console.WriteLine("Servizio attivo...");}catch (Exception exc){System.Console.WriteLine(exc.Message);}ConsoleKeyInfo k;do{k = System.Console.ReadKey();}while (k.Key != ConsoleKey.Enter);System.Console.WriteLine("Fermo il servizio");pnReg.Stop();}}}[/CODE]and this the "client-side" code:[CODE]using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net;using System.Net.PeerToPeer;namespace TestPeerToPeerClient{class Program{static void Main(string[] args){try{PeerNameResolver resolver = new PeerNameResolver();PeerName peerName = new PeerName("TSFPeerServer", PeerNameType.Unsecured);PeerNameRecordCollection results = resolver.Resolve(peerName);System.Console.WriteLine("Risoluzione dei nomi completata.\n", peerName);System.Console.WriteLine("Risultati per il nome: {0}", peerName);System.Console.WriteLine();foreach (PeerNameRecord record in results){System.Console.Write("Commenti:");if (record.Comment != null){Console.Write(record.Comment);}System.Console.WriteLine();System.Console.Write("Dati:");if (record.Data != null){Console.Write(System.Text.Encoding.ASCII.GetString(record.Data));}System.Console.WriteLine();System.Console.WriteLine("Endpoints:");foreach (IPEndPoint endpoint in record.EndPointCollection){Console.WriteLine("\t Endpoint:{0}", endpoint);Console.WriteLine();}}Console.ReadKey();}catch (Exception e){System.Console.WriteLine(e.Message);}}}}[/CODE]the problem is that if this two piece of software are executed by two Windows XP SP2 computers all works fine. If one of them is a Windows Server 2008 the client could not recognize the each other!Have you got some hints?Thank you a lot!


