Port Punching and UDP woes
Hello all,
Pls read this little lengthy story :)
I'm trying to make a peer-to-peer file transfer appln that can work through NATs . For that i'm using the stunt protocol .
an ex: (the stunt protocol as i understood)
PeerA wants a file from PeerB , both behind NATs . Now peerA cannot access peerB , because PeerB's IP is hidden .
In the stunt protocol , an external stunt server is used , which has a known ip, and knows A's and B's external IPs and Ports . So when A needs a file , it first send a request to server , and the server in turn requests the B to send a (UDP) packet towards A (which may or maynot reach A (A's firewall and NAT) . This process will punch a port in the B's nat . Now server instructs A to connect to B using B's external ip/port . Thus a connection is established.
now my problem.
I'm writing this appln using an udp lib whos source is not available with me.
Each peer has a bult in server and client modules and that part works fine using direct addresses.
Now in working behind NATs , the server needs to know the external IPs of the peers . For that i have created a new udp socket , bound it with the peer's internal server port (reuse addr option) , that send "sync" packets to the external server , and the server echos back (by this method the external server knows the visible ips) . now the problem comes is that , i'm getting an inconsistent message receiving with this new socket . ie the echoed message send into this socket(from the external server) reaches randomly .
i have already seen some threads regarding this . but that doesn't help me.
hope you understood the whole problem :rolleyes:
any solution / comments ??
Thanks in advance.
Re: Port Punching and UDP woes
Don't use hole punching. Hole punching was an extremely interesting experiment, but at the end of the day, it's a hack that sometimes works and sometimes doesn't.
For modern systems, use UPnP and map a port in the router. Some users will not have UPnP turned on in their router, but it's easier to tell them to turn it on then to trouble-shoot failures in hole punching.
If you insist on hole punching, then there's source code available at the links I gave in this post still work: http://www.codeguru.com/forum/showthread.php?t=372822
Mike