• Web 多线程作业


     1 import java.io.PrintWriter;
     2 import java.net.ServerSocket;
     3 import java.net.Socket;
     4 
     5 public class Test {
     6     public static void main(String[] args) throws Exception {
     7         ServerSocket server = new ServerSocket(8888);
     8         while (true) {
     9             Socket s = server.accept();
    10             Processer p = new Processer(s);
    11             Thread t = new Thread(p);
    12             t.start();
    13         }
    14     }
    15 }
    16 
    17 class Processer implements Runnable {
    18     private Socket socket;
    19 
    20     public Processer(Socket s) { // TODO Auto-generated constructor stub
    21         this.socket = s;
    22     }
    23 
    24     @Override
    25     public void run() {
    26         try {
    27             PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
    28             out.println("HTTP/1.0 200 OK");
    29             out.println("Content-Type:text/html;charset=utf-8");
    30             out.println();
    31             out.println("<h1> Web test is OK </h1>");
    32             out.close();
    33         } catch (Exception ex) {
    34             ex.printStackTrace();
    35         } finally {
    36             try {
    37                 socket.close();
    38             } catch (Exception e) {
    39                 e.printStackTrace();
    40             }
    41         }
    42     }
    43 }
  • 相关阅读:
    Python if __name__ == "__main__" 的含义
    自己用
    phpstorm && pycharm
    API Design for C++ 一本书值得一看
    std::set 使用
    Using Windows Web Services
    SOA 好好了解下
    NI Measurement Studio Enterprise 8.6
    那天看看
    内存映射 那天自己改改
  • 原文地址:https://www.cnblogs.com/suiyun/p/3083336.html
Copyright © 2020-2023  润新知