Regarding p2p connection and c#
i just want to know how two application interact with each other across the internet. how one send s开发者_C百科ome message to other one because when IP is not fixed. please give me some coding tips by which a p2p apps connect other one across the internet when IP is not known.
please help me in detail.
Before trying to get into implementation details and coding tips, you'd better learn how P2P networks work in general, what are possible architectures, and so on (start on http://en.wikipedia.org/wiki/Peer-to-peer). Your question is too wide to "help you in detail".
Edit: To get in quicker, this can be handy: .NET P2P: Writing Peer-to-Peer Networked Apps with the Microsoft .NET Framework
The way that the Peer Channel netPeerTcpBinding in WCF works is that it uses a combination of the Peer Name Resolution Protocol and the Simple Service Discovery Protocol to discover the peers on the peer mesh.
SSDP works on the local subnet to discover peers to which you can directly connect. It does this through traditional network broadcast techniques.
PNRP, on the other hand, works across networks and over the internet by using IPv6. Since most networks don't yet support IPv6, Teredo is used to tunnel this communications over IPv4.
When the P2P mesh is published on the global cloud, the mesh name is sent to one of Microsoft's publically accessible / free to use PNRP seed servers. When new peers come online, they first ask these seed servers for a partial peer list. This list is then used to perform futher peer name resolution.
When a peer is resolved on the global cloud, it is typically resolved to an IPv6 address. Anytime that peer's address changes, this information is sent out over the mesh so that the other peers know about it.
This is essentially a distributed hash table: http://en.wikipedia.org/wiki/Distributed_hash_table
When you send data out on the mesh, this data is routed by the Peer Channel to the peers the sending machine directly knows about. Each of these peers then route to their well-known peers, etc. This continues until the message has been sent to all peers on the mesh.
This works over the internet (and even behind firewalls / NAT devices) thanks to Teredo and IPv6.
Usually this would happen via some sort of directory hosted on a server in a known location.
As Spender pointed out, you can't do this without using a server as a go-between. Would you expect to be able to visit a friend if you didn't know their address?
In other words, each of the two machines intending to establish a P2P conection would contact a known server to exchange connection information. After that they could in theory talk to each other.
However, it is likely that they are behind routers using NAT and therefore can't receive incoming packets without either opening ports on the router or resorting to some kind of technique to get around NAT.
精彩评论