How to connect a Socket server via HTTP proxy

后端 未结 8 1166
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-02 14:08

I have a piece of code to connect to a Socket server, and it works fine.

Socket socket = new Socket();
socket.connect(new InetSocketAddress(address, port));
         


        
8条回答
  •  梦毁少年i
    2021-02-02 14:30

    Am I correct in saying that what you want is to use the http proxy (for exemple squid) to establish a CONNECT method to a remote server (from http rfc 2616)? Basically, the connection goes like this:

         -open a socket to the proxy (host, port)
         -send text to the proxy with basic header 
         ....CONNECT remote.internethost.com:1494 HTTP/1.0
         ....User-Agent: Java Proxy Socket version 1.0a
         ....Host: remote.internethost.com
         ....Proxy-Authorization: Basic YourBase64usernamePasswordIfRequired
         -then, the proxy will return a http status code (multiline text string) and the actual socket (if successfull)
         -this is this socket that needs to be returned to the connection object
    

    That could be done with personal classes but the beauty would be to reuse the proxy classes for it. This way, all the handshake with the http proxy, especially the response code would be handled.

提交回复
热议问题