Chả kà có bài tập về lập trình web server. Mình tìm trên java2s đc cái code naỳ. Ai phân tích giúp mình đoạn code sau với
Mã:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ngoc1;
/**
*
* @author NgocTigerStyle
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
public class Ngoc1{
public static void main(String args[]) throws Exception {
ServerSocket ss = new ServerSocket(80);
while (true) {
BufferedReader in;
try (Socket s = ss.accept(); PrintStream out = new PrintStream(s.getOutputStream())) {
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String info = null;
while ((info = in.readLine()) != null) {
System.out.println("now got " + info);
if (info.equals(""))
break;
}
out.println("HTTP/1.0 200 OK");
out.println("MIME_version:1.0");
out.println("Content_Type:text/html");
String c = "<html> <head>Welcome to my Webserver</head><body> <h1> My name is Ngoc </br></h1></Body></html>";
out.println("Content_Length:" + c.length());
out.println("");
out.println(c);
}
in.close();
}
}
}
View more random threads:
Hiện nay trên thị trường xuất hiện rất nhiều loại thuốc bôi tăng kích thước dương vật được lăng xê là có khả năng làm tăng kích cỡ dương vật của cánh mày râu. Tuy nhiên không phải loại thuốc nào cũng...
Thuốc tăng kích thước chim có tác...