2013-02-11 43 views
3

我正在查看silvertunnel庫,但努力建立一個成功的連接。我遇到的問題是連接需要10分鐘才能輸出。我一直在尋找通過其tests之一,這是我的代碼:連接到TOR Java

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; 
} 
+0

的Tor可以大部分時間相當緩慢。確保運行TOR節點,以保持網絡活着! – 2013-02-16 17:39:27

回答

2

這個問題很簡單,當你使用silvertunnel API你不需要在URL中指定的協議,所以簡單地刪除http://應修復你的錯誤。

嘗試以下

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