⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpservers.java

📁 通讯计费系统
💻 JAVA
字号:
package cfq.fare.server;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import cfq.comm.utils.LogManager;
import cfq.fare.res_req.HttpResponse;


/**
 * 模拟话费查询服务器系统
 * @author cfq
 *
 */
public class HttpServers {
	
	ServerSocket server=null;
	Socket socket=null;
//	HttpResponse res=new HttpResponse();
	private static final  int port=9090;
	private boolean isShoutDown=true;
	
	//等待客户端的连接
	public void waitConnect(){
		try {
			 server=new ServerSocket(port);
		} catch (IOException e) {
			LogManager.addError(e.toString());
			System.out.println(e.toString());
			System.exit(1);//非正常退出
		}
		
		while(isShoutDown){
			try {
				socket=server.accept();
				SocketControl sc=new SocketControl();
				sc.controlSocket(socket);
				//res.responseText(socket);
				//res.responseFileContent(socket, "log//cfq_log_server-20081111  220036.log");
				//this.testSocket(socket);
			} catch (IOException e) {
				LogManager.addError(e.toString());
				e.printStackTrace();
			}
		}
	}
	
	
	//测试socket的连接
	public void testSocket(Socket socket){
		try {
			InputStream is=socket.getInputStream();
			byte [] b=new byte[1024];
			//把从输入流读入的字节放到byte数组里
			is.read(b);  
			String str=new String(b);
			System.out.println("***********"+str);  //把字节转换为字符串,并输出
			String html="<html><head><title>服务器端返回</title></head><body><hr><br>"+"单前系统时间:"+System.currentTimeMillis()+"</body></html>";
			OutputStream os=socket.getOutputStream();
			os.write(html.getBytes());
			os.flush();
			socket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	
	
	public boolean isShoutDown() {
		return isShoutDown;
	}
	public void setShoutDown(boolean isShoutDown) {
		this.isShoutDown = isShoutDown;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -