HTTP Server Based on boost: ASIO

Source: Internet
Author: User

HTTP Server Based on boost: ASIO
----
Blog, http://blog.csdn.net/shunqiziranhao007/article/details/8737629
Date, January 1, March 29, 2013
----
This is an example of the boost ASIO Library (I modified some code to achieve the following effect), and implemented HTTP request packets and HTTP response packets of http1.0. Very interesting.

----
HTTP
----
For details, see "Computer Network-top-down v4cn" p61.
For more information, see RFC 2616.

There are two types of HTTP packets: Request Message and Response Message.

----
HTTP Request Message
----
It consists of three parts: one request line, several first rows, and entity body.

The format of the request line is: method, space, Uri, space, Protocol version, for example,
GET/index.html HTTP/1.1 CRLF
Then there is the first line, as shown in figure
HOST: www.xxx.com CRLF
Connection: Close CRLF
CRLF
Finally, Entity

----
HTTP Response Message
----
Part 3: state line 1, first line of several rows, entity body. For example,

HTTP/1.1 200 OK CRLF
Connection: Close CRLF
Date:... CRLF
Server:... CRLF
Last-modified:... CRLF
Content-Length:... CRLF
Content-Type:... CRLF
Entity

----
The following is the program effect.

Root directory of the server,
Alan @ Alan-PC: HTTP $ pwd
/Home/Alan/test/HTTP
Alan @ Alan-PC: HTTP $ cat index.html
<HTML>
<HR>
<B> hello, HTTP Server Based on boost: ASIO! </B>
<HR>
</Html>

Enable the HTTP server,
Alan @ Alan-PC: Server $./http_server.exe 0.0.0.0 10080/home/Alan/test/HTTP

The client accesses the HTTP server,
Alan @ Alan-PC: client $./async_client.exe 0.0.0.0 10080/index.html
Content-Length XH: 78
Content-Type XH: text/html

<HTML>
<HR>
<B> hello, HTTP Server Based on boost: ASIO! </B>
<HR>
</Html>

The browser accesses the HTTP server,

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.