title: Java UDP hole punching example - connecting through firewall
body: <p>Lets say I have two computers. </p>
  
  <p>They know each others public and private IPs via <code>ice4j</code>.</p>
  
  <p>One client listening and the other one sending some string. </p>
  
  <p>I'd like to see this happen via UPD hole punching:</p>
  
  <pre><code>Let A be the client requesting the connection
  
  Let B be the client that is responding to the request
  
  Let S be the ice4j STUN server that they contact to initiate the connection
  --
  A sends a connection request to S
  
  S responds with B's IP and port info, and sends A's IP and port info to B
  
  A sends a UDP packet to B, which B's router firewall drops but it still
  punches a hole in A's own firewall where B can connect
  
  B sends a UDP packet to A, that both punches a hole in their own firewall,
  and reaches A through the hole that they punched in their own firewall
  
  A and B can now communicate through their established connection without 
  the help of S
  </code></pre>
  
  <h3>Could any one post pseudo examples of how to go about doing hole punching through symmetric NAT? Assuming there will be server S that will help to guess the port numbers and establish connection between the client A and B.</h3>
  
  <p>It would be nice if you accounted for double NAT as well. </p>
  
  <h3>NOTE:</h3>
  
  <p>You can use STUN to discover the IP and Port but you have to write your own code that would send the IP:Port to your server via <code>keepalive</code> technique.   </p>
  
  <p>Once one client identifies the other via unique ID on the server it will be provided with the other's client IP:port info to UDP hole punch the data it needs to send and receive.</p>
  
  <h3>Little update:</h3>
  
  <p>There is library that is showing up on the horizon for java check it out:<br>
  <a href="https://github.com/htwg/UCE#readme" rel="noreferrer">https://github.com/htwg/UCE#readme</a> </p>