How to send data over global internet like torrents do?

It's called Hole Punching, can be used for TCP or UDP. The concept is pretty simple actually:

  1. clients are giving their sockets information between intermediary server
  2. the server update the socket information (if there is a NAT or Proxy between client and server)
  3. server share the socket information to target client
  4. client connect on each through other socket information via peer-to-peer connection

Many of those are already in Github. Check it.