1 How do I convert a string to byte-type data?
Str.getbytes ().
2 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),
The Run method contains-
① 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, writes the method that handles the object--directly into the input stream, translates the request directly into the request object--greatly reducing the amount of code
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:
Status line, response header (header), Response Body (web Resource)
The corresponding attribute is passed into the object in its native data type and then converted directly internally to the output stream
Can be directly used out output, but it is more recommended to load on the buffered stream output, greatly accelerate the speed
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.
3 How do I optimize the program?
The write dead part is changed to a variable variable value.
To extract the common part, modify the common part as soon as possible--with the XML file configuration.
4 Web site can not be loaded out of the picture may be what reason?
The last request connection was not closed and a new request could not be initiated.
5 Why do I need to package the response as an object?
Facilitates subsequent processing, such as writing out a method inside a client directly calling the response object.
——
The task will be completed today
Re-reel today's content again.
① completed sending Web page, if the request file does not exist, return 404
② Optimization Code
③
6 threads have several states?
New, Ready (Runnable), run (start--running), block (wait), destroy after the Run method finishes.
7 How do I understand thread synchronization and asynchrony?
Synchronization: Each of the dry
Async: Sequential execution
2017-9-8-A-Webserver Project