基于socket的Http服务器
类似tomcat,做一次socket的 one req—> one Thread—> http 协议解析和响应
代码
//创建socket的服务端
@Slf4j
public class Server {
private static ServerSocket server = null;
static {
synchronized (Server.class) {
if (server == null)
try {
server = new ServerSocket(ServerParams.PORT);
} catch (IOException e) {
log.error("创建socket监听端口失败...", e);
}
}
}
static void init() throws Exception {
HttpThread.init();
while (true) {
Socket client = server.accept();
// 将请求仍入线程池
HttpThread.exec(client);