Connecting the server to the client for NAT

I made a server / client application in C #.

My question is the following: let them say that the client is behind NAT (like a router) and is trying to connect to the server. From the point of view of the server, the server knows only the external IP address of the client. How do you determine exactly which computer sends these packets for NAT? I understand that port forwarding from the client-side router is a common way to solve these problems, but if you look at applications such as Skype, port forwarding is not required to establish a proper connection between the server and, like many other clients, for NAT. This question can be set and vice versa (IE: client for the server behind NAT).

I am new to socket programming, so I would like to hear any recommendations or materials that I can read in order to fully understand this material.

+4
source share
1 answer

You do not have to worry about NAT at the application level. If you receive a message with an IP message 200.51.255.79, you can send a response to the same IP address. Routers will process NAT and then automatically route. This is not the case, for example, with port forwarding, but with NAT.

Skype works in a very interesting way to bypass port forwarding and firewalls using the server database of current ips and ports, where each user is waiting for a response. You should watch this online for a full explanation. This is a really good read =).

+2
source

Source: https://habr.com/ru/post/1441694/


All Articles