multwebserver.java

来自「多线程服务器功能: 从同一局域网的不同主机发起请求; 从同一机器的多个浏览器」· Java 代码 · 共 40 行

JAVA
40
字号
/**
 * This is a multthread web server responds for get mehtod 
 * return thml page or images like gif and jpeg.
 * author:庾欢 张娟 张维
 * date: 06.10.29
 */

import java.net.* ;


public final class MultWebServer
{
	public static void main(String argv[]) throws Exception
	{
		//Set the port number.
		//choose any port higher than 1024
		int port = 6788;
		
		//Establish the server socket that listens for incoming connection
		ServerSocket listenSocket = new ServerSocket(port);  

		//Process HTTP service requests in an infinite loop.
		while (true) {
			
			// Listen for a TCP connection request.
			Socket connectionSocket = listenSocket.accept();
			//Construct an object to process the HTTP request message.
			HttpRequest request = new HttpRequest(connectionSocket);

			//Create a new thread to process the request.
			Thread thread = new Thread(request);

			// Start the thread.
			thread.start();
		}
	}
}


⌨️ 快捷键说明

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