1 Reply Latest reply: Apr 18, 2011 7:23 PM by EJP RSS

    How to use SOCKS in Java?

    856127
      I use 100% working socks and I can't connect through my application.

      SocketAddress proxyAddr = new InetSocketAddress("1.1.1.1", 12345);
      Proxy pr = new Proxy(Proxy.Type.SOCKS, proxyAddr);


      try
      {
      HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(pr);
      con.setConnectTimeout(proxyTimeout * 1000);
      con.setReadTimeout(proxyTimeout * 1000);
      con.connect();

      System.out.println(con.usingProxy());
      }
      catch(IOException ex)
      {
      Logger.getLogger(Enter.class.getName()).log(Level.SEVERE, null, ex);
      }

      So what am I doing wrong? If I'll use HTTP with some HTTP proxy all is working but not with SOCKS.

      The exception is:

      18.04.2011 16:02:33 rateme.Enter run
      SEVERE: null
      java.net.SocketException: Connection refused
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:405)
      at java.net.Socket.connect(Socket.java:529)
      at sun.net.NetworkClient.doConnect(NetworkClient.java:158)
      at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
      at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
      at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
      at sun.net.www.http.HttpClient.New(HttpClient.java:306)
      at sun.net.www.http.HttpClient.New(HttpClient.java:323)
      at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:970)
      at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:949)
      at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:836)
      at rateme.Enter.run(Enter.java:64)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
      at java.util.concurrent.FutureTask.run(FutureTask.java:138)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:662)
      18.04.2011 16:02:33 rateme.Enter run