三门峡营销招聘网:我下载了一个程序,但为什么运行是错误的
来源:百度文库 编辑:查人人中国名人网 时间:2024/05/01 01:56:40
import java.io.*;
import java.net.*;
/**
* 这个类实现了一个简单的单线程的代理服务器
*/
public class SimpleProxyServer {
/** 主函数解析参数并把参数传递给runServer */
public static void main(String[] args) throws IOException {
try {
// 检查参数的个数
if (args.length != 3)
throw new IllegalArgumentException("Wrong number of args.");
String host = args[0];
int remoteport = Integer.parseInt(args[1]);
int localport = Integer.parseInt(args[2]);
// 显示开始信息
System.out.println("Starting proxy for " + host + ":" +
remoteport + " on port " + localport);
runServer(host, remoteport, localport); // 永不返回
}
catch (Exception e) {
System.err.println(e);
System.err.println("Usage: java SimpleProxyServer " +
"<host> <remoteport> <localport>");
}
}
/**
* 这个方法运行一个单线程的代理服务器,它在指定的本地端口上
* 代理一个主机上的远程端口。它用不返回。
*/
public static void runServer(String host, int remoteport, int localport)
throws IOException {
// 创建一个ServerSocket来监听连接
ServerSocket ss = new ServerSocket(localport);
final byte[] request = new byte[1024];
byte[] reply = new byte[4096];
while(true) {
Socket client = null, server = null;
try {
// 等待一个本地端口的连接
client = ss.accept();
final InputStream from_client = client.getInputStream();
final OutputStream to_client = client.getOutputStream();
try { server = new Socket(host, remoteport); }
catch (IOException e) {
PrintWriter out = new PrintWriter(to_client);
out.print("Proxy server cannot connect to " + host + ":"+
remoteport + ":\n" + e + "\n");
out.flush();
client.close();
continue;
}
final InputStream from_server = server.getInputStream();
final OutputStream to_server = server.getOutputStream();
Thread t = new Thread() {
public void run() {
int bytes_read;
try {
while((bytes_read=from_client.read(request))!=-1) {
to_server.write(request, 0, bytes_read);
to_server.flush();
}
}
catch (IOException e) {}
try {to_server.close();} catch (IOException e) {}
}
};
// 开始客户端到服务器请求线程的运行
t.start();
int bytes_read;
try {
while((bytes_read = from_server.read(reply)) != -1) {
to_client.write(reply, 0, bytes_read);
to_client.flush();
}
}
catch(IOException e) {}
// 服务器关闭同我们的连接,那么我们关闭与客户端的连接
// 这将使另外一个线程退出
to_client.close();
}
catch (IOException e) { System.err.println(e); }
finally {
try {
if (server != null) server.close();
if (client != null) client.close();
}
catch(IOException e) {}
}
}
}
}
import java.net.*;
/**
* 这个类实现了一个简单的单线程的代理服务器
*/
public class SimpleProxyServer {
/** 主函数解析参数并把参数传递给runServer */
public static void main(String[] args) throws IOException {
try {
// 检查参数的个数
if (args.length != 3)
throw new IllegalArgumentException("Wrong number of args.");
String host = args[0];
int remoteport = Integer.parseInt(args[1]);
int localport = Integer.parseInt(args[2]);
// 显示开始信息
System.out.println("Starting proxy for " + host + ":" +
remoteport + " on port " + localport);
runServer(host, remoteport, localport); // 永不返回
}
catch (Exception e) {
System.err.println(e);
System.err.println("Usage: java SimpleProxyServer " +
"<host> <remoteport> <localport>");
}
}
/**
* 这个方法运行一个单线程的代理服务器,它在指定的本地端口上
* 代理一个主机上的远程端口。它用不返回。
*/
public static void runServer(String host, int remoteport, int localport)
throws IOException {
// 创建一个ServerSocket来监听连接
ServerSocket ss = new ServerSocket(localport);
final byte[] request = new byte[1024];
byte[] reply = new byte[4096];
while(true) {
Socket client = null, server = null;
try {
// 等待一个本地端口的连接
client = ss.accept();
final InputStream from_client = client.getInputStream();
final OutputStream to_client = client.getOutputStream();
try { server = new Socket(host, remoteport); }
catch (IOException e) {
PrintWriter out = new PrintWriter(to_client);
out.print("Proxy server cannot connect to " + host + ":"+
remoteport + ":\n" + e + "\n");
out.flush();
client.close();
continue;
}
final InputStream from_server = server.getInputStream();
final OutputStream to_server = server.getOutputStream();
Thread t = new Thread() {
public void run() {
int bytes_read;
try {
while((bytes_read=from_client.read(request))!=-1) {
to_server.write(request, 0, bytes_read);
to_server.flush();
}
}
catch (IOException e) {}
try {to_server.close();} catch (IOException e) {}
}
};
// 开始客户端到服务器请求线程的运行
t.start();
int bytes_read;
try {
while((bytes_read = from_server.read(reply)) != -1) {
to_client.write(reply, 0, bytes_read);
to_client.flush();
}
}
catch(IOException e) {}
// 服务器关闭同我们的连接,那么我们关闭与客户端的连接
// 这将使另外一个线程退出
to_client.close();
}
catch (IOException e) { System.err.println(e); }
finally {
try {
if (server != null) server.close();
if (client != null) client.close();
}
catch(IOException e) {}
}
}
}
}
错误信息?
我下载了一个程序,但为什么运行是错误的
下载了photoshopcs的程序但“运行安装时发生错误,确保已完成前面的安装并关闭其他程序”我应该怎么做?
为什么我的WINDOWS2000很多程序运行是都会有"程序错误"然后关闭?
我只运行了百度一个程序,为什么我的CPU使用率是百分之百呢?
我已经成功编写完成了一个vc++的MFC程序,但为什么点击运行没反应呢?
为什么我安装的Visual C++运行程序的时候老是提示有一个错误?
我下载了一个程序 但他默认是用写字板打开的
VB程序的运行错误“7”超出内存是为什么
为什么我的U盘不能安全删除,总说还有一个程序在运行,但又不知道是哪个程序.
本人下载的TurboC2.0为什么编写完的程序不能运行(程序没错误),我该怎么办