Sending UDP packets over the Internet

I am trying to learn some of the features of P2P / decentralized networks. My question is the following. Let's say I have two machines named comp1 and comp2. Now comp1 is installed in my home network behind the router, and comp2 is in my office and behind the router. Is it possible for me to send UDP packets back and forth over the Internet, like this, assuming, of course, that the ports are forwarded correctly? To better understand what I'm learning, I'm trying to figure out how a new node will detect existing nodes without using a central server.

Thanks!

+4
source share
2 answers

Assuming that, as you said, the ports are redirected correctly, you can send UDP packets to 2 clients behind the router.

Using multicast can be a good way to locate clients on your local intranet, however it does not have widespread ISP support (at least here in the UK), so you can not rely on it. Multicast is used by many device discovery platforms such as mDNS (used by Apple Bonjour)

http://en.wikipedia.org/wiki/Multicast

(It mainly works with clients who subscribe to groups, and then sends messages to this group)

I think that the best way to open new clients via the Internet is to have one server with which new clients will contact, so that he knows that they exist, then a centralized server will tell about all other clients about you. This is used, for example, in P2P games such as Modern Warfare 2, and this is what the โ€œTrackersโ€ do in the BitTorrent protocol.

This is not completely decentralized, but perhaps it is easiest to implement and the most reliable.

+3
source

To add to the Dotmister answer, if the ports are not redirected correctly (for example, the router is not statically configured to forward ports), you will need to look at something like UDP hole punching . In any case, in order to discover a new node without any central server, you have to rely on some kind of Multicast.

+1
source

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


All Articles