开发者

how does HTTP Tunneling work?

I was taking a look at the JHttpTunnel library and this piece of code in OutBoundSocket.java got me a bit confused.

 public void connect() throws IOException{
close();

String host=getHost();
int port=getPort();

String request="/index.html?crap=1 HTTP/1.1";

Proxy p=getProxy();
if(p==null){
  socket=new Socket(host, port);
  request="POST "+request;
}
else{
  String phost=p.getHost();
  int pport=p.getPort();
  socket=new Socket(phost, pport);
  request="POST http://"+host+":"+port+request;
}
socket.setTcpNoDelay(true);

in=socket.getInputStream();
out=socket.getOutputStream();
out.write(request.getBytes());
out.write(_rn);
out.write(("Content-Length: "+getContentLength()).getBytes());
out.writ开发者_StackOverflow社区e(_rn);
out.write("Connection: close".getBytes());
out.write(_rn);
out.write(("Host: "+host+":"+port).getBytes());
out.write(_rn);

out.write(_rn);
out.flush();

sendCount=getContentLength();

}

This seems to directly open a socket to the server. Wont the firewall block this?


Firewall can block it but it depends on the configuration, you could ask won't a proxy block this and the answer would be the same. The code above is just a small part of a bigger picture... But generally HTTP tunneling should open a socket to the HTTP server and encapsulate a plain stream over HTTP requests, in order to send these requests a socket between the HTTP client and the HTTP server is needed and this is what you see here. What you don't see in this code is the encapsulation stuff. I hope that helped.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜