I’ve made a server/client application in C#.
My question is the following: Let’s say a client is behind an NAT (Like a router) and tries to connect to a server. From the server’s perspective, the server only knows the client’s external IP address. How do you determine exactly which computer to send the packets to that is behind an NAT? I understand port forwarding from the router on the client’s end is a common way of solving these type of problems but if you look at applications like Skype, port forwarding is not necessary to properly establish a connection between the server and however many clients behind the NAT. This question can be asked vice-versa as well (I.E: client to server behind NAT).
I’m pretty new at socket programming so I’d love to hear any guidelines or materials that I can read over to fully understand this stuff.
You shouldn’t worry about NAT in the application layer. If you receive a message with an IP say 200.51.255.79 you can send the answer to the same IP. Routers will handle the NAT and further routing automatically. It’s not like this with port forwarding of course but it is with NAT.
Skype works in a very interesting way to get around port forwarding and firewalls using a server sided database of current ips and ports where each user is waiting for a response. You should look that up on the internet for a full explanation. It’s a really good read =).