当前位置: 技术问答>java相关
终于找到了代理服务器的编源代码,哈哈哈哈哈!!!!
来源: 互联网 发布时间:2015-02-16
本文导语: /************************************* * 一个基础的代理服务器类 ************************************* */ import java.net.*; import java.io.*; public class HttpProxy extends Thread { static public int CONNECT_RETRIES=5; static public int ...
/*************************************
* 一个基础的代理服务器类
*************************************
*/
import java.net.*;
import java.io.*;
public class HttpProxy extends Thread {
static public int CONNECT_RETRIES=5;
static public int CONNECT_PAUSE=5;
static public int TIMEOUT=50;
static public int BUFSIZ=1024;
static public boolean logging = false;
static public OutputStream log=null;
// 传入数据用的Socket
protected Socket socket;
// 上级代理服务器,可选
static private String parent=null;
static private int parentPort=-1;
static public void setParentProxy(String name, int pport) {
parent=name;
parentPort=pport;
}
// 在给定Socket上创建一个代理线程。
public HttpProxy(Socket s) { socket=s; start(); }
public void writeLog(int c, boolean browser) throws IOException {
log.write(c);
}
public void writeLog(byte[] bytes,int offset, int len, boolean browser) throws IOException {
for (int i=0;i0) {
os0.write(bytes,0,ir);
if (logging) writeLog(bytes,0,ir,true);
}
else if (ir0) {
os1.write(bytes,0,ir);
if (logging) writeLog(bytes,0,ir,false);
}
else if (ir
* 一个基础的代理服务器类
*************************************
*/
import java.net.*;
import java.io.*;
public class HttpProxy extends Thread {
static public int CONNECT_RETRIES=5;
static public int CONNECT_PAUSE=5;
static public int TIMEOUT=50;
static public int BUFSIZ=1024;
static public boolean logging = false;
static public OutputStream log=null;
// 传入数据用的Socket
protected Socket socket;
// 上级代理服务器,可选
static private String parent=null;
static private int parentPort=-1;
static public void setParentProxy(String name, int pport) {
parent=name;
parentPort=pport;
}
// 在给定Socket上创建一个代理线程。
public HttpProxy(Socket s) { socket=s; start(); }
public void writeLog(int c, boolean browser) throws IOException {
log.write(c);
}
public void writeLog(byte[] bytes,int offset, int len, boolean browser) throws IOException {
for (int i=0;i0) {
os0.write(bytes,0,ir);
if (logging) writeLog(bytes,0,ir,true);
}
else if (ir0) {
os1.write(bytes,0,ir);
if (logging) writeLog(bytes,0,ir,false);
}
else if (ir