一、代码
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/
![在这里插入图片描述](https://img-blog.csdnimg.cn/b76d5a872aab43d0b47fcf203ac305d5.png)
三、控制台![在这里插入图片描述](https://img-blog.csdnimg.cn/6b02c3a36bc74ca5868b857c98852de0.png)