Reputation: 2773
Please consider the following basic network setup :
As you can see, machine A is running a homemade server application, called myserverapp. This application is made in C, and listens on port 5000 for incoming packets/connections. It follows basic networking concepts, through IP sockets. With the above configuration, only machines A and B can reach this application (through 192.168.1.60:5000).
By setting a network port forwarding rule in the first router's configuration, I can allow 1.2.3.4:5000 to resolve to 192.168.1.60:5000 locally. Please note that this requires an actual router setup.
My objective here is to allow access to ./serverapp, without setting up a forwarding rule in the router's configuration. I would like my application to request worldwide IP binding by itself. As examples, Skype (not that much of a good example these days), Transmission, and many others, are reachable worldwide, but do not require me to set up a port forwarding rule for them.
Now, I am aware that this is a very recurrent question, but here are some additional circumstances :
I tried punching a UDP hole to allow peer-to-peer communication, but apparently, my router doesn't like it. Even though I can synchronise a list of peers through a relay server, the peers cannot reach each other afterwards. I am also unable to reach them using the nc
utility, on the port given by the server.
UPnP is not enabled on many routers, even nowadays, and seems to be controversial. At the moment, this is not an option. Plus, note that this would also require a router setup (activating UPnP).
(from comments) My router does not forward any port by default : only those I set up. Plus, I am looking for a solution working on more routers than just mine.
Also note that this is programming-related : I know this is mostly a network problem, but I am looking implementation solutions. I am not looking for help setting up the network itself (actually, this is precisely what I want to avoid).
Now, my question would be : is there a well-known technique, applicable in C, to allow peer-to-peer communication behind a router ? Are there associated libraries ? Many pieces of P2P software can be ran on most computers, even mine (for which I was unable to make a UDP hole), and I just can't figure out how they achieve this.
Upvotes: 2
Views: 808
Reputation: 6163
http://en.wikipedia.org/wiki/Interactive_Connectivity_Establishment
Use the above Wikipedia article as a starting point where you get links to specific IETF standards regarding connectivity establishment behind IPv4 NAT. By crawling from that article you will get more and better information than you can ever get at stack exchange, as it's a pretty much known field.
The basic answer is that techniques based on STUN work in some environments while techniques based on TURN work in all environments except those that explicitly block traffic. The TURN based techniques are basically based on the idea that the machines that are not part of Internet use IPv4 UDP/TCP NAT to connect to a machine that is in Internet and on top of those connections they can exchange messages with each other.
Upvotes: 1
Reputation: 25129
Many of the applications you quote use central servers without NAT, if only to bounce the packets of. Both client devices contact a central server, which effectively puts the two endpoints in touch with each other.
What you want to do is called NAT traversal. Here are two well known ways to do this: STUN (see here) and TURN (see here).
Upvotes: 1