I am trying to make a peer 2 peer audio/video application, but behind NAT and behind firewall causing my application failture, i figure out that Skype does it and other application does also other approach, then i decided to use this approach which will allow my application to work behind NAT office/home.
UDP Hole punching:
So far, tried hping2 and netcat. Server, pc1 behind nat/firewall and pc2 behind nat/firewall
local/1$ nc -u 14141 -l # ME, step 1
remoteServer$ echo "hello" | nc -p 53 -u xx.23.xx.xx 14141 # My server, to say hello
nc: Write error: No route to host
local/2$ hping2 -c 1 -2 -s 14141 -p 53 xx.21.xx.xx # Me from second terminal making a hole
remoteServer$ echo "hello" | nc -p 53 -u xx.23.xx.xx 14141 # My server again say hell
local/1 $ nc -u 14141 -l # ME, step 1 was running and it received "hello" now
hello
But local/1 how to get the hello, without hping2 or what is exactly hping2? Can anyone suggest? Or how i can just do the A (local) B(server) C(my friend) communicate with peer 2 peer using this method?
Useful links: http://www.masquerade.cz/en/nat-tunel-metodou-udp-hole-punching-v-jazyce-java/
Follow up: UPnP is best solution? But it looks for the very next hop, so in that case it will fail for this road map (if i am not wrong):
Me (behind NAT) -> MyOffice (with router, 50 laptops) -> ISP1 -> ISP2 -> FriendOffice (router,开发者_JS百科 90 laptops) -> Friend (behind NAT)
What many p2p applications do is to connect to the nearest router and ask them to open a port to themselves. Read about UPnP and NAT-PMP protocols.
精彩评论