Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8fd16c3

Browse files
committed
Adding HTTP Server example in index page.
1 parent2f62ca4 commit8fd16c3

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

‎libs/network/doc/index.rst

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
.. :Date: Nov 9, 2010
1616
.. :Version: 0.8
1717
.. :Description: Complete user documentation, with examples, for the :mod:`cpp-netlib`.
18-
.. :Copyright: Copyright Glyn Matthews, Dean Michael Berris 2008-2010.
18+
.. :Copyright: Copyright Glyn Matthews, Dean Michael Berris 2008-2011.
1919
.. Distributed under the Boost Software License, Version
2020
.. 1.0. (See accompanying file LICENSE_1_0.txt or copy at
2121
.. http://www.boost.org/LICENSE_1_0.txt)
@@ -40,7 +40,7 @@ The :mod:`cpp-netlib` allows you to write semantically consistent code for
4040
making different kinds of higher level network applications.
4141

4242
The library allows for writing simple code for simple C++ HTTP client
43-
applications like:
43+
applications:
4444

4545
..code-block::c++
4646

@@ -53,6 +53,34 @@ applications like:
5353
client::responseresponse_ =client_.get(request);
5454
std::string body = body(response_);
5555

56+
The library also allows for writing simple C++ HTTP servers:
57+
58+
..code-block::c++
59+
60+
namespace http = boost::network::http;
61+
62+
struct handler;
63+
typedef http::server<handler> http_server;
64+
65+
struct handler {
66+
void operator() (http_server::request const &request_,
67+
http_server::response &response_) {
68+
response = http_server::response::stock_reply(
69+
http_server::response::ok, "Hello, world!");
70+
}
71+
72+
void log(http_server::string_type const & info) {
73+
std::cerr << "ERROR: " << info << '\n';
74+
}
75+
76+
};
77+
78+
int main(int arg, char * argv[]) {
79+
handlerhandler_;
80+
http_server server_("0.0.0.0", "8000",handler_);
81+
server_.run();
82+
}
83+
5684
The:mod:`cpp-netlib` is being developed for eventual submission toBoost_.
5785

5886
Download

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp