title: Java - How to connect using SOCKS5
body: <p>How can I create a socket connection using a SOCKS5 proxy with Java?</p>
  
  <p>I have found several ways of connecting with socks4 but no one with socks5. Is this possible in Java?</p>
  
  <p>This is what I got so far, but it doesn't seem to work. When I try to connect with the socket, it stays forever until it says connection time out.</p>
  
  <pre><code>SocketAddress sa = InetSocketAddress.createUnresolved("127.0.0.1", TOR_SOCKS_PORT);
  Proxy proxy = new Proxy(Proxy.Type.SOCKS, sa);
  return new Socket(proxy);
  </code></pre>