<p>From a <a href="http://www.joelonsoftware.com/items/2007/01/26.html" rel="nofollow noreferrer">Joel's post on Copilot</a>:</p>

<blockquote>
  <p>Direct Connect! We’ve always done
  everything we can to make sure that 
  Fog Creek Copilot can connect in any
  networking situation, no matter  what
  firewalls or NATs are in place. To
  make this happen, both parties  make
  outbound connections to our server,
  which relays traffic on their  behalf.
  Well, in many cases, this isn’t
  necessary. So version 2.0 does 
  something rather clever: it sets up
  the initial connection through our 
  servers, so you get connected right
  away with 100% reliability. But then 
  once you’re all connected, it quietly,
  in the background, looks for a  way to
  make a direct connection. If it can’t,
  no big deal: you just keep  relaying
  through our server. If you can make a
  direct peer-to-peer  connection, it
  silently shifts your data onto the
  direct connection. You  won’t notice
  anything except, probably, much faster
  communication.</p>
</blockquote>

<p>How do they change the server connection to a P2P connection?</p>

[{'answer_id': 44208, 'author': 'Steve Gury', 'author_id': 1578, 'author_profile': 'https://Stackoverflow.com/users/1578', 'pm_score': 1, 'selected': False, 'text': '<p>There is a technique called "<a href="https://en.wikipedia.org/wiki/Hole_punching_(networking)" rel="nofollow noreferrer">Hole Punching</a>" that works well with "Cone" NAT (Cone is a technical familly of router). That\'s not an 100% sure technique, today, it works well with UDP on about 80% of the router.</p>\n\n<p>There is some implementations of library to realize Hole Punching: <a href="http://sourceforge.net/projects/stun/" rel="nofollow noreferrer">STUN</a> (<a href="http://en.wikipedia.org/wiki/STUN" rel="nofollow noreferrer">wikipedia</a>)</p>\n'}, {'answer_id': 44236, 'author': 'Adam Davis', 'author_id': 2915, 'author_profile': 'https://Stackoverflow.com/users/2915', 'pm_score': 4, 'selected': True, 'text': "<p>It's pretty tricky and interesting.  I'm sure I have some details wrong, but the overview is this:</p>\n\n<p>The programs can already talk to each other through Joel's server, so they can exchange information with each other and Joel's server.  Further, Joel has their external IP addresses, and they give joel information about their internal IP addresses.</p>\n\n<p>They decide to try this hole punch technique.  Computer A initiates a TCP connection with Computer B using B's external IP address.  It won't go through, but what it does is tell's A's router that it needs to allow incoming packets from B on a given port.</p>\n\n<p>Computer B does the same thing, but its message gets through to A since A's router opened a port/ip combination that matches what B sent (there's some port magic that happens here - this is non trivial, but doable).</p>\n\n<p>B's router remembers that B initiated a connection with A on a given port and IP, and so A's packets now flow into B past their router correctly as well.</p>\n\n<p>So it's actually pretty straight forward, but the implementation has details, especially regarding how ports are given to new TCP connections, and how NAT routers <em>typically</em> deal with TCP requests and how they map to external ports.  These details are the interesting, and difficult, bit.</p>\n\n<p>-Adam</p>\n"}, {'answer_id': 44255, 'author': 'Jack M.', 'author_id': 3421, 'author_profile': 'https://Stackoverflow.com/users/3421', 'pm_score': 1, 'selected': False, 'text': "<p>I believe the simple version is that they drop the server connection and replace it with the P2P connection.</p>\n\n<p>Something along the lines of:</p>\n\n<ol>\n<li>Machine1 connects to copilot's servers.</li>\n<li>Machine1 connects to copilot's servers.</li>\n<li>Machine1 connects to copilot's servers.</li>\n<li>Machine2 subsequently connects, and they begin screen sharing.</li>\n<li>Machine2 opens a port intended for Machine1 to connect to.</li>\n<li>Machine1 tries to connect to the now open port on Machine2.</li>\n</ol>\n\n<p>If this connection is established:</p>\n\n<ol>\n<li>The connection to copilot's servers is severed.</li>\n<li>Data is instead transfered over the direct (P2P) connection between the two machines.</li>\n</ol>\n"}]
['https://Stackoverflow.com/questions/44205', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4269/']