English 中文(简体)
NAT, P2P and Multiplayer
原标题:
  • 时间:2009-11-21 19:19:03
  •  标签:
  • p2p
  • nat

How can an application be designed such that two peers can communicate directly with each other (assuming both know each other s IPs), but without outgoing connections? That s, no ports will be opened. Bitorrent for example does it, but multiplayer games (as far as I know) require port forwarding.

最佳回答

I m not sure what you mean by No Outgoing Connections, I m going to assume like everyone else you meant no Incoming Connections (they are behind a NAT/FW/etc).

The most common one mentioned so far is UPNP, which in this context is a protocol that allows you as a computer to talk to the Gateway and say forward me this port because I want someone on the outside to be able to talk to me. UPNP is also designed for other things, but this is the common thing for home networking (Actually it s one of many definitions).

There are also more common and slightly more reliable ways if you don t own the network. The most common is called STUN but if I recall correctly there are a few variants. Basically you use a third party server that allows incoming connections to try and coordinate a communication channel. Basically, what you do is send a UDP packet to you re peer, which will open up you re NAT for a response, but gets dropped on you re peer s NAT (since no forwarding rule exists yet). Through the connection to the intermediary, they are then told to do the same, which now opens up their NAT, and matches the existing rule in you re NAT. Now the communications can proceed. Their is a variant of this which will allow a TCP/IP connection as well by sending SYN and SYN-ACK messages with some coordination.

The Wikipedia articles I ve linked to has links to the relevant rfc s for these protocols on precisely how they work. Essentially it comes down to, there isn t an easy answer, as this is a very network centric problem.

问题回答

You need a "meeting point" in the network somewhere: the participants "meet" at a "gateway" of some sort and the said "gateway function" takes care of the forwarding.

At least that s one way of doing it: I won t try to comment on the details of Bittorrent... I am sure you can google for links.

UPNP dealt with this mostly in the recent years, but the need to open ports is because the application has been coded to listen on a specific port for a response.

Ports beneath 1024 are called "registered" because they ve been assigned a port number because a company paid for it. This doesn t mean you couldn t use port 53 for a webserver or SSH, just that most will assume when they see it that they are dealing with DNS. Ports above 1024 are unregistered, so there s no association - your web browser, be it Internet Explorer/Firefox/etc, is using an unregistered port to send the request to the StackOverflow webserver(s) on port 80. You can use:

netstat -a

..on windows hosts to see what network connections are currently established, including the port involved.

UPNP can be used to negotiate with the router to open and forward a port to your application. Even bit-torrent needs at least one of the peers to have an open port to enable p2p connections. There is no need for both peers to have an open port however, since they both communicate with the same server (tracker) that lets them negotiate and determine who has an open port.

An alternative is an echo-server / relay-server somewhere on the internet that both peers trust, and have that relay all the traffic. The "problem" with this solution is that the echo-server needs to have lots of bandwidth to accomodate all connected peers since it relays all the traffic rather than establish p2p connections.

Check out EchoWare: http://www.echogent.com/tech.htm





相关问题
Maintaining network integrity in peer-to-peer network

I am looking for information on techniques, algorithms, etc. on how to maintain network integrity in a dynamic peer-to-peer network. Both practical implementations, academic papers and anything else ...

Open-source p2p videoconferencing in Flash or Java?

I want to build a community website with videoconferencing functionality integrated. I would prefer to provide this from within the browser, so I m looking for a Java- or Flash-based solution. Also, ...

JXTA Applications on the iPhone

I m creating a P2P Java application in JXTA, for simple messaging between peers. I want to create a similar program on the iPhone, that will be able to talk with this java JXTA program. Is this ...

NAT, P2P and Multiplayer

How can an application be designed such that two peers can communicate directly with each other (assuming both know each other s IPs), but without outgoing connections? That s, no ports will be opened....

The most efficient DHT

What is the most efficient DHT? I am looking for name and/or some kind of implementation or related work, but I am not looking for the one that is most used. Efficient in terms of CPU execution ...

P2P or Distributed System implementation

I have the work of implementing a distributed system of nodes (like p2p nodes) each of these nodes (lets say A,B,C and D) perform certain functions and need to interact with each other for various ...

热门标签