6

This topic resembles this thread

I'm rather new to the topic of network programming, never having done anything but basic TCP/UDP on a single local machine. Now I'm developing an application that will need P2P network support. More specifically I will need the application to connnect and communicate across the internet preferably without the use of a server to do the matchmaking between the clients.

I'm aware and assuming that almost all users are behind a router which complicates the process since neither clients will be able to initialize a direct connection to the other.

I know UPnP is an option to allow port forwarding without having the users configure this manually, but as of now this is not an option. Is they any way to achieve my goal or will I need that server?

Community
  • 1
  • 1
Kasper Holdum
  • 12,993
  • 6
  • 45
  • 74

5 Answers5

6

You'll need a server to exchange IP address and such. As the other thread literally points out, the only way of guaranteeing a connection is to proxy through a server. Most peer to peer systems use UPnP and NAT Hole Punching (this method needs a server relaying port information and only works with UDP) to establish a connection in most cases.

NAT Hole Punching works by both clients establishing a connection to a server, then the both try to connect directly to a port that the other has relayed to the other. Most UDP NAT remember the IP address and port for a short time, so although the data never made it to the other end (not that this matters with UDP) the other client will try to connect a few moments later to that report as the NAT would expect the reply.

ewanm89
  • 919
  • 5
  • 22
6

A very good reading, made just for you :-), is RFC 5128, "State of Peer-to-Peer (P2P) Communication across Network Address Translators (NATs)".

bortzmeyer
  • 34,164
  • 12
  • 67
  • 91
3

Check out the P2P channel with WCF: http://msdn.microsoft.com/en-us/library/cc297274.aspx

It works quite well.

codekaizen
  • 26,990
  • 7
  • 84
  • 140
  • Yes. It uses the Peer Naming Resolution and IPV6. – codekaizen Jul 26 '09 at 01:17
  • IPv6 basically doesn't use NAT as there is a big enough address space anyway. But most ISPs don't support it yet. And consumer NAT need updated firmware to know to just bridge IPv6 connections. – ewanm89 Jul 26 '09 at 01:22
  • Right, but with Teredo and IPV6 tunneling, you don't need to worry about network support. – codekaizen Jul 26 '09 at 02:10
  • Do you've a link to any articles/papers discussing those teqniques with relation to .NET? – Kasper Holdum Jul 26 '09 at 03:39
  • WCF Peer channel takes care of it for you using Windows PNRP and Peer Networking. It's pretty robust and fairly simple to grab a WCF Peer Channel demo/sample and try it yourself. – codekaizen Jul 26 '09 at 06:30
  • IPv6 tunneling is not possible in all cases, and the point is we are trying to minimise user configuration. Not maximise it. – ewanm89 Jul 26 '09 at 10:13
  • @ewanm89 have you used Peer Channel? I've never had a lot of configuring to do... and never had problems with IPv6 tunneling. In v2.0 of Peer-to-peer it just worked. – codekaizen Jul 26 '09 at 19:48
2

Ignoring UPnP (which only works with some routers, unfortunately), and no central server, I'm not sure it would be possible to create a direct connection when both users are behind a NAT.

Kitsune
  • 9,101
  • 2
  • 25
  • 24
  • I'm aware of the NET punching /hole punching tecnique, but it requires a server. – Kasper Holdum Jul 26 '09 at 01:07
  • I missed that link in your post the first time I went through. Without having a central server (to help negotiate the connection), I don't believe it's possible. – Kitsune Jul 26 '09 at 01:11
  • 2
    What sad world are we living in, when two computers cannot connect to eachother directly without having special configured hardware or a middleman to help them. – Kasper Holdum Jul 26 '09 at 01:13
  • IPv6 would help a lot, it should make the UDP trick a lot easier, while still giving the same security. – Kitsune Jul 30 '09 at 15:28
1

Well to avoid a server to "matchmake" you could do what skype does and set up some peers as relays to others behind NATs. You wll always need some sort of boot strapping mechanism, so a centralized server will probably play into your system somehow (depending on what your developing, of course).

Junier
  • 1,622
  • 1
  • 15
  • 21