📄 service.java
字号:
import java.net.Socket;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.DataOutputStream;
public class Service {
private Service() {
}
public static void service(Socket clientSocket) throws IOException {
System.out.println(Thread.currentThread().getName() + ": Service.service(" + clientSocket + ") BEGIN");
try {
DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream());
out.writeBytes("HTTP/1.0 200 OK\r\n");
out.writeBytes("Content-type: text/html\r\n");
out.writeBytes("\r\n");
out.writeBytes("<html><head><title>Countdown</title></head><body>");
out.writeBytes("<h1>Countdown start!</h1>");
for (int i = 10; i >= 0; i--) {
System.out.println(Thread.currentThread().getName() + ": Countdown i = " + i);
out.writeBytes("<h1>" + i + "</h1>");
out.flush();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
out.writeBytes("</body></html>");
} finally {
clientSocket.close();
}
System.out.println(Thread.currentThread().getName() + ": Service.service(" + clientSocket + ") END");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -