有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

与TorJava的连接

我正在查看silvertunnel库,但努力建立成功的连接。我遇到的问题是,连接需要超过10分钟才能给出输出。我正在查看其中一个tests,这是我的代码:

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) 个答案

  1. # 1 楼答案

    问题很简单,当您使用silvertunnel API时,不需要在url中指定协议,因此只需删除http://就可以修复错误

    试试下面的方法

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