简体   繁体   English

任何协议的简单正向代理

[英]simple forward proxy for any protocol

I am wanting to develop a centralized java server that accepts multiple connections for any type of network traffic IE FTP, HTTP, HTTPS, RDP, etc. The only goal is to forward it off to the expected destination and return the response back to the requester. 我想开发一个集中的Java服务器,该服务器可以接受任何类型的网络流量(例如,IE FTP,HTTP,HTTPS,RDP等)的多个连接。唯一的目标是将其转发到预期的目标,并将响应返回给请求者。 I have no idea where to start with this because the only information I am finding is related to forwarding java servlet requests and some info on forwarding HTTP. 我不知道从哪里开始,因为我发现的唯一信息与转发Java Servlet请求以及有关转发HTTP的一些信息有关。 Is there anyway to simply forward it off, or would it require handling every protocol differently? 无论如何,有没有将其转发出去的方法,还是要求以不同的方式处理每个协议?

public void run () {
    InetSocketAddress address = (InetSocketAddress)this.socket.getRemoteSocketAddress();
    try {
        InputStreamReader isr = new InputStreamReader(this.socket.getInputStream());
        BufferedReader br = new BufferedReader(isr);
        OutputStream os = this.socket.getOutputStream();
        String ipAddress = address.getHostName();
        Log.d("client","A client has connected from: "+ipAddress);

        //TODO forward the client inputstream to the destination

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try{
            this.socket.close();
        } catch (Exception e) {}
    }
}

Every protocol is different, unless you want to, and can, force them all into one straightjacket like HTTP's CONNECT verb. 每种协议都是不同的,除非您愿意并且可以将它们强制像HTTP的CONNECT动词一样放在一个直线外套中。 You will have to research what proxy protocols the intended clients are capable of using. 您将必须研究目标客户端可以使用哪些代理协议。

More probably you should be looking at using SOCKS, in an existing implementation. 您很可能应该在现有实现中使用SOCKS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM