C # peer-to-peer networking - router bypass

I want to encode a peer-to-peer chat program in C #. I am trying to understand how the network will work. I know that the concept is that each peer is a client and a server at the same time. It can connect and connect. But my question is: how do you connect to the computer behind the router without forwarding the port to this computer? I know things like Bittorrent, no problem. I planned to use the tracker to store a list of peers and the ports they are listening to, but I still don’t understand how to get through the problem with the router. Can someone explain?

+4
source share
3 answers

In addition to John Faminella’s answer, you might consider using the UPNP service, which many consumer network devices support.

+3
source

You are right, this is not trivial. The problem is NAT, or the transfer of network addresses . In fact, the IP address that you have on your local network is unique, but in the wider context of the public Internet, many people behind the same router will have the same public IP address. Thus, given the IP and some data, you cannot say exactly which person on the other end should receive it.

The most effective and simplest solution is for a third party to mediate the connection by inserting itself into the data stream. Instead of each person in the chat being a “client” and a “server” at the same time, there was only one server, and it was in a well-known public place; then everyone connects to it. The server then manages the messages and sends messages to people during the chat.

There are other solutions. For example, instead of using a well-known server, you can use the well-known port (s): all communications take place on that port (s). Then you do not need a server, but all endpoints must have this port open, which requires preliminary configuration.

+4
source

I assume that you mean in the NAT environment, and if so read and understand Peer- to- peer communication through network addressers (Ford, Srisuresh and Kegel .

The basic concept is that each client must initiate a connection that opens a path through a NAT device. It may be useful to refer to the Pidgin source code for some ideas.

+3
source

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


All Articles