当前位置: 技术问答>java相关
JAVA制作代理服务器的可行性?
来源: 互联网 发布时间:2015-03-28
本文导语: 原来要用VC做代理服务器,现在必须用JAVA制作,由于对java不怎么了解,所以希望大家帮我分析一下可行性,以及用JAVA制作的优缺点 | 非常简单 非常方便 ibm上就有现成的 http://www-900.ibm.com/devel...
原来要用VC做代理服务器,现在必须用JAVA制作,由于对java不怎么了解,所以希望大家帮我分析一下可行性,以及用JAVA制作的优缺点
|
非常简单
非常方便
ibm上就有现成的
http://www-900.ibm.com/developerWorks/java/index.shtml
非常方便
ibm上就有现成的
http://www-900.ibm.com/developerWorks/java/index.shtml
|
/*************************************
* 一个基础的代理服务器类
*************************************
*/
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