sending udp packet from WAN to a local computer without setting port forwarding on router C++

2k Views Asked by At

I have a server with a public IP, I want to send some UDP Packet data from the server over the WAN to a computer connected behind a router. I have the public IP of my home connection and I have the public IP of the server, I am also able to get the MAC addresses if necessary. I am using Windows Sockets for this. I know this can all be done via port forwarding on the router which I did and everything is working fine, but I want to know how this can be done through C++ code.

Applications like utorrent or Skype are able to send data directly to a PC from the WAN through the router and to my computer without having to port forward. Just wondering how this is all done.

Thanks in advance.

1

There are 1 best solutions below

2
On

For TCP, you don't have to do a thing. Just initiate the connection from the PC. The router will know the responses has to be routed back to the PC.

UDP is tricky you as you need router support. Applications typically use NAT-PMP to achieve this. The wikipedia entry mentions both uTorrent and Skype. If you want to see how they do it listen on UDP port 5351.

There's another technique called UDP hole punching which requires a third party which is directly addressable by both sides.