Reputation: 4869
I've been trying to make a p2p type application. My idea was to just create a webserver type program that listens on a certain socket. However if I try this from anywhere outside my local network the requests never get through to the listening socket. How do other p2p software get around this I'm using the same ports as skype and other programs (8080)
Upvotes: 1
Views: 2033
Reputation: 8180
This link explains the 'hole punching' techniques in some detail:
http://www.brynosaurus.com/pub/net/p2pnat/
Excerpt:
3.2 Establishing Peer-to-Peer Sessions
Suppose client 'A' wants to establish a UDP session directly with client 'B'. Hole punching proceeds as follows:
'A' initially does not know how to reach 'B', so 'A' asks 'S' for help establishing a UDP session with 'B'.
'S' replies to 'A' with a message containing 'B''s public and private endpoints. At the same time, 'S' uses its UDP session with 'B' to send 'B' a connection request message containing 'A''s public and private endpoints. Once these messages are received, 'A' and 'B' know each other's public and private endpoints.
When 'A' receives 'B''s public and private endpoints from 'S', 'A' starts sending UDP packets to both of these endpoints, and subsequently “locks in” whichever endpoint first elicits a valid response from 'B'. Similarly, when 'B' receives 'A''s public and private endpoints in the forwarded connection request, 'B' starts sending UDP packets to 'A' at each of 'A''s known endpoints, locking in the first endpoint that works. The order and timing of these messages are not critical as long as they are asynchronous.
Upvotes: 0
Reputation: 347
Skype falls back to use port 80 or 4** (dont remember) if it can not connect to port 8080.
I was had a problem with it when I tried to launch a local Apache instance when Skype was already running.
Skype provides a setting to change the port it uses, but then you must forward this port on your router/firewall/whatever.
Maybe this you could use a similiar approach for your application?
Upvotes: 0
Reputation: 597885
There are many tricks to workaround NATs and firewalls.
If both parties are connected to an external central server, then they can exchange IP/Ports with each other through that server as a proxy. If party A then tries to connect to party B and gets blocked, they can switch roles and party B can try to connect to party A. That in itself will get through many situations, unless both parties are both behind NATs/firewalls.
There are UDP- and TCP-based techniques for punching holes through NATs to allow traffic that would normally be blocked.
Some routers support uPNP for configuring port forwarding rules dynamically.
Upvotes: 0
Reputation: 6773
There is such a thing as UPnP that some applications use. I think Skype plays lots of tricks to make it easy to use with firewalls. It will even use port 80, as that is most of the time open. Most p2p applications that I've seen, require a proper firewall/NAT configuration.
Upvotes: 1