Connection to TOR Java

8.6k Views Asked by At

I was looking at the silvertunnel library but struggling to build a successful connection. The problem I'm having is that the connection takes over 10 minutes to give output. I was looking through one of their tests, and this is my code:

public boolean tryConnOLD() throws IOException {

    try {
        // define remote address
        String remoteHostname = "http://test.silvertunnel.com";
        int remotePort = 80;
        TcpipNetAddress remoteAddress = new TcpipNetAddress(remoteHostname, remotePort);
        // get TorNetLayer instance and wait until it is ready
        NetLayer netLayer = NetFactory.getInstance().getNetLayerById(NetLayerIDs.TOR);
        netLayer.waitUntilReady();
        // open connection to remote address - this connection is tunneled through the TOR anonymity network
        netSocket = netLayer.createNetSocket(null, null, remoteAddress);
        InputStream is = netSocket.getInputStream();

        String content = CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8));
        Closeables.closeQuietly(is);

        is.close();
        System.out.println(is.read());
        java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");

        if(s.hasNext()) {
         System.out.println(s.next());   
         System.out.println();   
        }

        return true;

    } catch (IOException ex) {

    } finally {
        netSocket.close();
    }

    return false;
}
1

There are 1 best solutions below

0
On

The problem is quite simple, when you use the silvertunnel API you dont need to specify the protocol in the url, so simply removing http:// should fix your errors.

try the following

                        //remove http://   
String remoteHostname = "test.silvertunnel.com";