Hello, everyone.In network programming, a beginner, but already quite good with the basic principles.I wrote a small multi-threaded chat on C ++ sockets.Everything works well, but only in my local server, where I am a server, and the laptops are clients.I realized that probably the easiest way is to buy VDS on Windows(well, or take a cheap one on a line, but rewrite it under a line, respectively).But I am more than sure that you can do without it.Having a little searching in the internet, I realized you can somehow forward the ports on the router.But I got a router recently(no, I’m not dinosaur, I was just 17 and I had to earn money myself), so I have little experience with him.In general, if I'm right, tell me how to forward ports on the router so that the client behind NAT can connect with me.If not, then tell me how.
Thank you in advance.
  • C ++ Sockets.How to establish a connection behind a NAT?

    In general, if I'm right, then tell me how to forward ports on the router so that the client behind the NAT can connect with me.But if not, then tell me how it is correct.

    C ++ needs to be removed, it has nothing to do with it.
    – Clear Cod Jun 28 '19 at 10:14
  • Clear Cod, thanks – Odd Owl Jun 28 '19 at 10:25
  • And what kind of router do you have? – Ashamed Anteater Jun 28 '19 at 10:38
  • The boy just has ChSV rolls over.He recognized C ++, the sockets, but no one could boast.I would have gone to the street for a walk, I could have met a woman, and she can brag about it. by sabzh - port forwarding on the router – Rural Outlaw Jun 28 '19 at 10:51
  • Rural Outlaw, you write everything correctly.I was bombarded when I was counting on a question about STUN in C ++ or is there a NAT traversal through an external server, but it turned out that this is an idiotic question about forwarding, which is googled once or twice :) – Annoying Antelope Jun 28 '19 at 10:57
  • yes you are right here all the pros in everything. – Alien Pirate Jun 28 '19 at 12:50
  • Clear Cod, why not, someone can prompt the ready-made UPnP libraries for C ++. – Alien Pirate Jun 28 '19 at 13:08

3 Answers 3

realized that you can somehow forward the ports on the router
You can
But you must have a white address given to you by the provider.T.you should not be behind the NAT provider.Otherwise, it will not work.

so that the client behind the NAT can communicate with me.
A client behind a NAT can connect anywhere, at least to you, at least somewhere else.
The main thing that you were not behind NAT'om, well, or you must have ports forwarded.
Hmm, such a long answer, but[[Jump]] for some reason did not give an answer to the afftor question.
It's not at all clear what the Berkeley, C ++ sockets are for, if they are talking about port forwarding.

pogugli.com /? 340321
Just enter the model of your router.
Work for NAT can be made a function of your application(such function happens in torrent-clients, for example), but this is not the easiest functionality.

Most consumer 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 you to reverse port forwarding through NAT.To do this, a request is first made to discover the router, then a request is made for the mapping itself.In detail, and with the analysis of traffic using both methods, see this article:
https://habr.com/en/post/279969/

But it is worth first to clarify whether your router supports UPnP.An enterprise-level equipment usually does not support UPnP for security reasons.