j av a实现http代理服务public void writeLog(byte[]bytes, int offset, int len,boolean browser)throws IOExc eption{for(int i=0; i len; i++)writeLog((int)bytes[offs et+i],brow s er);
//默认情况下 日志信息输出到
//标准输出设备
//派生类可以覆盖它public String processHostName(String url,String host, int port,Socket sock) {java.text.DateFormat cal=java.text.DateFormat.getDateTimeInstance();System.out.println(c al.format(new java.util.Date())+-+url+
+sock.getInetAddres s()+\nreturn host;
//执行操作的线程public void run() {
String line;
String host;int port=80;
S oc ket outbound=null;try{s ocket.s etSoTimeout(TIMEOUT);
InputStream is=s oc ket.getInputStream();
OutputStream os=null;
try{
//获取请求行的内容line=host=int state=0;boolean space;w hile(true) {int c=is.read();if(c==-1)break;if(logging)wr iteLo g(c, true);spac e=Character.isWhitespac e((char)c);sw itch(state) {case0:if(space)c ontinue;state=1;case 1:if(space) {state=2;c ontinue;
line=line+(char)c;break;case2:if(space)c ontinue; //跳过多个空白字符state=3;case3:if(space) {state=4;
//只取出主机名称部分
String host0=host;int n;n=host.indexOf( //if(n!=-1)host=host.substring(n+2);n=host.indexOf(‘/’);if(n!=-1)host=host.substring(0,n);
//分析可能存在的端口号n=host.indexOf( :if(n!=-1) {port=Integer.parseInt(host.substring(n+1));
host=host.substring(0,n);host=processHostName(host0,host,port, socket);if(p arent !=null) {hos t=parent;port=parentP ort;int retry=CONNECT_RETRI ES;while(retry-- !=0) {try{outbound=new S oc ket(host,port);break;
} catch(Exc eption e) {
//等待
Thread.s leep(CONNECT_PAUSE);if(o utb o un d==nu ll)break;outbound.s etS oT imeout(T IMEOUT);o s=outb ound.getOutput S tream();os.write(line.getBytes());os.write(‘ ‘);os.write(host0.getBytes());os.write(‘ ‘);p ip e(is,outb ound.getInputS tream(),o s,
s oc ket.getOutputS tream());break;host=host+(char)c;break;
} catch(IOException e) {
} catch(Exc eption e) {
}final ly{try{socket.close();
} catch(Exception e1) {try{outbound.c lo s e();
} catch(Exc eption e2) {void pipe(InputStream is0, InputStream is 1,OutputStream os0,OutputStream os 1) throws IOException{try{int ir;byte bytes[]=new byte[BUFSIZ];w hile(true) {try{if((ir=is 0.read(bytes))0) {os0.write(bytes,0, ir);
if(logging)wr iteLo g(byte s,0, ir, true);
} else if(ir 0)break;
} catch(InterruptedIOExc eption e) {try{if((ir=is 1.read(bytes))0) {os 1.write(bytes,0, ir);if(logging)writeLo g(byte s,0, ir, fals e);
} else if(ir 0)break;
} catch(InterruptedIOExc eption e) {
} catch(Exception e0) {
System.out.println(Pipe异常:+e0);static public void startProxy(int port,Class clobj) {ServerSocket ssock;try{ssock=new ServerSocket(port);w hile(true) {
Class[] sarg=new Class[1];
Object[] arg=new Object[1];
sarg[0]=Socket.clas s;try{java.lang.reflect.Constructor cons=clobj
.getDeclaredConstructor(sarg);arg[0]=ssock.accept();c ons.newInstanc e(arg); //创建HttpProxy或其派生类的实例} catch(Exc eption e) {
Socket esock=(Socket)arg[0];try{esock.close();
} catch(Exception ec) {
} catch(IOException e) {static public void stopProxy(){try{if(null!=HttpProxy.s oc ket)
HttpProxy.socket.close();
} catch(IOException e) {e.printStackTrac e();
//测试用的简单main方法static public void main(String args[]) {
Sys tem.out.println(在端口808启动代理服务器\n
HttpProxy.lo g=S ys tem.out;
HttpProxy.lo gging=fals e;
HttpProxy.s tartProxy(808,HttpProxy.c las s);}
来自 http://c henyu-hz.iteye.c om/b lo g/1493227
火数云怎么样?火数云主要提供数据中心基础服务、互联网业务解决方案,及专属服务器租用、云服务器、专属服务器托管、带宽租用等产品和服务。火数云提供洛阳、新乡、安徽、香港、美国等地骨干级机房优质资源,包括BGP国际多线网络,CN2点对点直连带宽以及国际顶尖品牌硬件。专注为个人开发者用户,中小型,大型企业用户提供一站式核心网络云端服务部署,促使用户云端部署化简为零,轻松快捷运用云计算!多年云计算领域服务经...
如今我们网友可能较多的会选择云服务器、VPS主机,对于虚拟主机的话可能很多人不会选择。但是我们有些外贸业务用途的建站项目还是会有选择虚拟主机的。今天看到的Stablehost 商家虚拟主机在黑五期间也有四折优惠,对于这个服务商而言不是特别的喜欢,虽然他们商家和我们熟悉的老鹰主机商有些类似,且在后来老鹰主机改版和方案后,Stablehost 商家也会跟随改版,但是性价比认为不如老鹰主机。这次黑色星期...
进入6月,各大网络平台都开启了618促销,腾讯云目前也正在开展618云上Go活动,上海/北京/广州/成都/香港/新加坡/硅谷等多个地区云服务器及轻量服务器秒杀,最低年付95元起,参与活动的产品还包括短信包、CDN流量包、MySQL数据库、云存储(标准存储)、直播/点播流量包等等,本轮秒杀活动每天5场,一直持续到7月中旬,感兴趣的朋友可以关注本页。活动页面:https://cloud.tencent...