Java tunnel and tcp proxy

人盡茶涼 提交于 2021-02-10 15:13:53

问题


I need to tunnel through a tcp proxy. Within Java, the proxy types are only socks, direct or HTTP. So in the example below a socket is being created then the proxy object is being created from the socketAddress and the type is socks.
How can I specify the proxy is TCP?

    SocketAddress addr = new InetSocketAddress("socks.example.com", 1080);
    Proxy proxy = new Proxy(Proxy.Type.SOCKS, addr);
    Socket socket = new Socket(proxy);
    InetSocketAddress dest = new InetSocketAddress("server.example.org", 1234);
    try {
        socket.connect(dest);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return isValidated;

回答1:


You want a DIRECT proxy to Localhost on the port you set up to tunnel to the destination. For example if your tunnel is set up to go from 4000 (Local) to 3389 (on the host you really want to connect to) the destination is Localhost, 1000, proxy type Direct. See SSH tunneling via JSch



来源:https://stackoverflow.com/questions/50473633/java-tunnel-and-tcp-proxy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!