Sending UDP packets over the Internet

cskwrd picture cskwrd · Mar 31, 2011 · Viewed 10.3k times · Source

I'm trying to learn some of the ins and outs of P2P/decentralized networks. My question is the following. Say I have two machines named comp1 and comp2. Now comp1 is setup on my home network behind a router, and comp2 is located in my office at also behind a router. Is it possible for me to send UDP packets back and forth across the Internet like this assuming of course that ports are forwarded properly? To offer more insight on what I'm investigating, I'm trying to figure out how a new node would discover existing nodes without the use of a central server.

Thank you!

Answer

Adam Casey picture Adam Casey · Mar 31, 2011

Assuming, as you said the ports are forwarded correctly you can send UDP packets to 2 clients behind router's.

A good way of detecting clients on a local intranet may be using Multicast, however this does not have widespread support on ISP's (At least here in the UK) so cannot be relied upon. Multicast is used by many device discovery platforms, such as mDNS (used inApple's Bonjour)

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

(It basically works by clients subscribing to groups, and then sending messages to that group)

I think the best way of discovering new clients over the internet is to have one server which new clients contact to let it know they exist, then the centralised server will tell all the 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 isn't entirely decentralised but it's probably the easiest to implement, and the most reliable.