S
S
Sazoks2019-06-28 09:59:22
Computer networks
Sazoks, 2019-06-28 09:59:22

Berkeley sockets. How to establish a connection behind NAT?

Hello. I'm new to network programming, but I've already got a good grasp of the basic principles. Wrote a small multi-threaded chat on C++ sockets. Everything works well, but only in my LAN, where I am the server and the laptops are the clients. After a little thought, I realized that probably the easiest way is to buy a VDS on Windows (well, or take a cheap one on the line, but rewrite it under the line, respectively). But I am more than sure that you can do without it. After a little searching on the internet, I realized that you can somehow forward the ports on the router. But I recently got a router (no, I'm not a dinosaur, I'm just 17 and had to earn money myself), so I have little experience with it. In general, if I'm right, then tell me how to forward ports on the router so that the client behind NAT can connect with me. If not, please tell me how.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Ronald McDonald, 2019-06-28
@Zoominger

Hmm, such a long answer, but for some reason Artem did not give an answer to the author's question.
It is not entirely clear what the Berkeley sockets, C ++ and chat have to do with it, if the question is about port forwarding.
pogugli.com/?340321 Enter
your router model only.

V
Vladimir Dubrovin, 2019-06-28
@z3apa3a

Work behind NAT can be made a function of your application (such a function happens in torrent clients, for example), but this is not the easiest functionality.
Most home routers support UPnP SSDP/IGD and some support NAT PMP.
https://en.wikipedia.org/wiki/Internet_Gateway_Dev...
https://en.wikipedia.org/wiki/NAT_Port_Mapping_Protocol
Both protocols allow reverse port forwarding through NAT. To do this, first a request is made to discover the router, then a request is made to actually map. Details and analysis of traffic for both methods are in this article:
https://habr.com/en/post/279969/
But first you should check if your router supports UPnP. Enterprise-grade hardware typically does not support UPnP for security reasons.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question