2017-9-7-a-Webserver Project

Source: Internet
Author: User

1 is the ReadLine method of the buffered stream blocked?
Is

2 request (get), Response (return), separate format what? What are the rules for HTTP?
HTTP request Format

One request, one response, no request, no response.

3 What is the HTTP protocol?
Hypertext Transfer Protocol is the communication protocol between the browser and the server.

4 What is the HTTP request made up of?
Request line, message header, message body.

5 What is the request line format?
Method Request-uri Http-versioncrlf
(CR: Refers to a carriage return in a different system LF: refers to a newline--CRLF in a different system: newline to the very beginning, i.e. the end of the line)
Such as:
Get/index.html Http/1.1crlf
Post/login.html Http/1.1crlf

6 What is DNS?
Binds the domain name to the specified IP address, and the domain name is converted to the corresponding IP address when accessed.

7 What is the role of CRLF?
Indicates when the line ends.

8 Can the server use BR (BufferedReader) to quickly read the request header (CRLF line-wrapping) on a line? What if it doesn't work? What is the specific reading process?
No, BR newline only (does not intelligently identify line breaks under different systems)
Use StringBuilder to read a character one character at a point until it is read to CR (10).
The specific reading process: To determine whether the number of times and the last time is equal to 10 and 13, if it is to jump, if not, will be the value of the conversion to char after adding builder and assign the value of the time to C2, for the next judgment
These two whitespace characters must be removed with String.Trim () due to the CRLF of the last character.
int C1 = -1,C2 =-1
while ((C1 = In.read ())! =-1) {
if (c1 = = && C2 = = 13) {
Break
}
Bulider.append ((char) C1);
C2 = C1;
}
String line = builder.tostring (). Trim ();

9 What port does the HTTP request access by default?
80

10 The URI contained in the request header will request a Web page from the server.

11 Do I need to include is in the first time when I get the request header while (true)?
Not required, is gets a large segment, and the circular datum is a newline instead of retrieving the data again.

12 use while (true) or thread when you need to handle requests sent by multiple users at the same time?
Thread because it needs to process the other one at the same time, rather than finishing the process.

13 Why do I need to use a thread pool?
increase concurrency efficiency.

14 Do I need to separate the read request lines?
Is.

15 What is the process for reading HTTP requests?
Read Request Line
Read several lines (until the CRLF is read).
Reading the message body
Analyze request line requests for what resources

16 business logic to be extremely clear, a method to implement a function.

Server overall business process,
Create a new server to fetch requests, read processing requests, return request resources
Wrap the latter two processes into the Clietnhandler (new Class), and once a new request creates a new thread, it needs to be managed with a thread pool because of the number of threads.
The main process in ClientHandler is the Run method, the Run method (that is, the process of fetching, reading, processing the request),
① reads the request, converts the request item to an object, and facilitates subsequent retrieval to determine the returned data.
The object includes the request header and the message header lookup table, and the methods that handle the object are also written.
The message header lookup table must be instantiated before it is used, or it will not be used
The criteria for jumping out of a loop is to return a string length of 0 instead of full equal to null or "". (StringBuilder maintains an empty string internally by default)
② returns a request to instantiate the property of the response as an object.
The Request object contains:
Where the state value must be stored in a dictionary

From large to small, whether in the grasp of the big process, or perfect small branches have to be confident. Always hold the whole map.

17 What do you do first when you have a good idea?
Piling.

What is returned by the read () method of InputStream?
The next byte until the read is finished returns-1.

2017-9-7-a-Webserver Project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.