3

我正在查看silvertunnel库,但努力建立成功的连接。我遇到的问题是连接需要 10 多分钟才能提供输出。我正在查看他们的一项测试,这是我的代码:

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;
}
4

1 回答 1

3

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

尝试以下

                        //remove http://   
String remoteHostname = "test.silvertunnel.com";
于 2013-02-12T13:15:28.463 回答