一、代码
package com.jt.net;
import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class Tomcat {
public static void main(String[] args) throws IOException {
System.out.println("start server ...");
ServerSocket server=new ServerSocket(9999);
while(true){
Socket socket=server.accept();
System.out.println("hello client "+socket);
OutputStream out=socket.getOutputStream();
String content="HTTP/1.1 200\r\n" +
"Content-Type: text/html;charset=UTF-8\r\n"+
"\r\n"+
"<h1>hello client</h1>";
out.write(content.getBytes());
socket.close();
}
}
}
二、效果
http://localhost:9999/
三、控制台