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

Commit7a4c3c8

Browse files
committed
0.9.3 docs.
1 parent3df9c60 commit7a4c3c8

File tree

366 files changed

+39424
-14977
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

366 files changed

+39424
-14977
lines changed

‎0.9.3/.buildinfo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: 31a95735f192c1e856251f90a3552520
4+
tags: fbb0d17656682115ca4d033fb2f83ba1
File renamed without changes.

‎0.9.3/_images/ftp_uri.png

25 KB
Loading

‎0.9.3/_images/http_uri.png

20.2 KB
Loading

‎0.9.3/_images/mailto_uri.png

9.98 KB
Loading

‎0.9.3/_sources/contents.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.. _contents:
2+
3+
Contents
4+
--------
5+
6+
.. toctree::
7+
:maxdepth: 3
8+
9+
whats_new.rst
10+
getting_started.rst
11+
examples.rst
12+
in_depth.rst
13+
techniques.rst
14+
history.rst
15+
reference.rst
16+
references.rst

‎0.9.3/_sources/examples.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.. _examples:
2+
3+
Examples
4+
========
5+
6+
The :mod:`cpp-netlib` is a practical library that is designed to aid
7+
the development of applications for that need to communicate using
8+
common networking protocols. The following set of examples describe a
9+
series of realistic examples that use the :mod:`cpp-netlib` for these
10+
kinds of application. All examples are built using CMake.
11+
12+
HTTP examples
13+
`````````````
14+
15+
The HTTP component of the :mod:`cpp-netlib` contains a client and server.
16+
The examples that follow show how to use both for programs that can be
17+
embedded into larger applications.
18+
19+
.. toctree::
20+
:maxdepth: 1
21+
22+
examples/http/http_client
23+
examples/http/simple_wget
24+
examples/http/hello_world_server
25+
examples/http/hello_world_client
26+
examples/http/atom_reader
27+
examples/http/twitter_search
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
.. _atom_reader:
2+
3+
******************
4+
Atom feed reader
5+
******************
6+
7+
The next examples show some simple, more practical applications using
8+
the HTTP client. The first one reads a simple Atom_ feed and prints
9+
the titles of each entry to the console.
10+
11+
.. _Atom: http://en.wikipedia.org/wiki/Atom_(standard)
12+
13+
The code
14+
========
15+
16+
.. code-block:: c++
17+
18+
#include "atom.hpp"
19+
#include <boost/network/protocol/http/client.hpp>
20+
#include <boost/foreach.hpp>
21+
#include <iostream>
22+
23+
int main(int argc, char * argv[]) {
24+
using namespace boost::network;
25+
26+
if (argc != 2) {
27+
std::cout << "Usage: " << argv[0] << " <url>" << std::endl;
28+
return 1;
29+
}
30+
31+
try {
32+
http::client client;
33+
http::client::request request(argv[1]);
34+
request << header("Connection", "close");
35+
http::client::response response = client.get(request);
36+
atom::feed feed(response);
37+
38+
std::cout << "Feed: " << feed.title()
39+
<< " (" << feed.subtitle() << ")" << std::endl;
40+
BOOST_FOREACH(const atom::entry &entry, feed) {
41+
std::cout << entry.title()
42+
<< " (" << entry.published() << ")" << std::endl;
43+
}
44+
}
45+
catch (std::exception &e) {
46+
std::cerr << e.what() << std::endl;
47+
}
48+
49+
return 0;
50+
}
51+
52+
Building and running ``atom_reader``
53+
====================================
54+
55+
.. code-block:: bash
56+
57+
$ cd ~/cpp-netlib-build
58+
$ make atom_reader
59+
60+
And to run the example from the command line to access the feed that
61+
lists of all the commits on cpp-netlib's master branch:
62+
63+
.. code-block:: bash
64+
65+
$ ./example/atom_reader https://github.com/cpp-netlib/cpp-netlib/commits/master.atom
66+
67+
Diving into the code
68+
====================
69+
70+
Most of this will now be familiar. The response is passed to the
71+
constructor to the ``atom::feed`` class, which parses the resultant
72+
XML. To keep this example as simple as possible, `rapidxml`_, a
73+
header-only XML parser library, was used to parse the response.
74+
75+
.. _`rapidxml`: http://rapidxml.sourceforge.net/
76+
77+
A similar example using RSS feeds exists in
78+
``libs/network/example/rss``.

‎_sources/hello_world_client.txtrenamed to ‎0.9.3/_sources/examples/http/hello_world_client.txt

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Since we have a "Hello World" HTTP server, let's then create an HTTP client to
88
access that server. This client will be similar to the HTTP client we made
99
earlier in the documentation.
1010

11-
TheCode
11+
Thecode
1212
========
1313

1414
We want to create a simple HTTP client that just makes a request to the HTTP
@@ -44,33 +44,27 @@ server that we created earlier. This really simple client will look like this:
4444
return 0;
4545
}
4646

47-
Building theClient
48-
===================
47+
Buildingand runningtheclient
48+
===============================
4949

5050
Just like with the HTTP Server and HTTP client example before, we can build this
5151
example by doing the following on the shell:
5252

5353
.. code-block:: bash
54-
55-
$ cd ~/cpp-netlib
56-
$ g++ -o hello_world_client \
57-
> libs/network/example/http/hello_world_client.cpp \
58-
> -I$BOOST_ROOT \
59-
> -I. \
60-
> -L$BOOST_ROOT/stage/lib \
61-
> -lboost_system \
62-
> -pthread
54+
55+
$ cd ~/cpp-netlib-build
56+
$ make hello_world_client
6357

6458
This example can be run from the command line as follows:
6559

66-
::
60+
.. code-block:: bash
6761

68-
$ ./hello_world_client 127.0.0.18000
62+
$ ./example/hello_world_clienthttp://127.0.0.1:8000
6963

7064
.. note:: This assumes that you have the ``hello_world_server`` running on
7165
localhost port 8000.
7266

73-
Diving into theCode
67+
Diving into thecode
7468
====================
7569

7670
All this example shows is how easy it is to write an HTTP client that connects
@@ -92,8 +86,9 @@ perform the request via HTTP:
9286

9387
http::client client;
9488
http::client::request request("http://my.webservice.com/");
95-
http::client::response =
89+
http::client::response =
9690
client.post(request, "application/xml", some_xml_string);
9791
std::data = body(response);
9892

99-
93+
The next set of examples show some more practical applications using
94+
the :mod:`cpp-netlib` HTTP client.

‎_sources/hello_world_server.txtrenamed to ‎0.9.3/_sources/examples/http/hello_world_server.txt

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ client side, we'll see how we can then use the same abstractions on the server
99
side. In this example we're going to create a simple HTTP Server in C++ using
1010
:mod:`cpp-netlib`.
1111

12-
TheCode
12+
Thecode
1313
========
1414

1515
The :mod:`cpp-netlib` provides the framework to develop embedded HTTP
@@ -38,12 +38,12 @@ simple response to any HTTP request.
3838

3939
int
4040
main(int argc, char * argv[]) {
41-
41+
4242
if (argc != 3) {
4343
std::cerr << "Usage: " << argv[0] << " address port" << std::endl;
4444
return 1;
4545
}
46-
46+
4747
try {
4848
hello_world handler;
4949
server server_(argv[1], argv[2], handler);
@@ -53,40 +53,36 @@ simple response to any HTTP request.
5353
std::cerr << e.what() << std::endl;
5454
return 1;
5555
}
56-
56+
5757
return 0;
5858
}
5959

6060
This is about a straightforward as server programming will get in C++.
6161

62-
Building theServer
63-
===================
62+
Buildingand runningtheserver
63+
===============================
6464

6565
Just like with the HTTP client, we can build this example by doing the following
66-
on the shell::
66+
on the shell:
67+
68+
.. code-block:: bash
6769

68-
$ cd ~/cpp-netlib
69-
$ g++ -o hello_world_server \
70-
> libs/network/example/http/hello_world_server.cpp \
71-
> -I$BOOST_ROOT \
72-
> -I. \
73-
> -L$BOOST_ROOT/stage/lib \
74-
> -lboost_system \
75-
> -pthread
70+
$ cd ~/cpp-netlib-build
71+
$ make hello_world_server
7672

7773
The first two arguments to the ``server`` constructor are the host and
7874
the port on which the server will listen. The third argument is the
7975
the handler object defined previously. This example can be run from
8076
a command line as follows:
8177

82-
::
78+
.. code-block:: bash
8379

84-
shell$ ./hello_world_server 0.0.0.0 8000
80+
$ ./example/hello_world_server 0.0.0.0 8000
8581

8682
.. note:: If you're going to run the server on port 80, you may have to run it
8783
as an administrator.
8884

89-
Diving into theCode
85+
Diving into thecode
9086
====================
9187

9288
Let's take a look at the code listing above in greater detail.
@@ -115,9 +111,9 @@ This header contains all the code needed to develop an HTTP server with
115111
``hello_world`` is a functor class which handles HTTP requests. All
116112
the operator does here is return an HTTP response with HTTP code 200
117113
and the body ``"Hello, <ip>!"``. The ``<ip>`` in this case would be
118-
the IP address of the client that made the request.
114+
the IP address of the client that made the request.
119115

120-
There are a number of pre-defined stock replies differentiated by
116+
There are a number of pre-defined stock replies differentiated by
121117
status code with configurable bodies.
122118

123119
All the supported enumeration values for the response status codes can be found
@@ -134,10 +130,10 @@ the port on which the server will listen. The third argument is the
134130
the handler object defined previously.
135131

136132
.. note:: In this example, the server is specifically made to be single-threaded.
137-
In a multi-threaded server, you would invoke the ``hello_world::run`` member
138-
method in a set of threads. In a multi-threaded environment you would also
139-
make sure that the handler does all the necessary synchronization for shared
140-
resources across threads. The handler is passed by reference to the server
141-
constructor and you should ensure that any calls to the ``operator()`` overload
133+
In a multi-threaded server, you would invoke the ``hello_world::run`` member
134+
method in a set of threads. In a multi-threaded environment you would also
135+
make sure that the handler does all the necessary synchronization for shared
136+
resources across threads. The handler is passed by reference to the server
137+
constructor and you should ensure that any calls to the ``operator()`` overload
142138
are thread-safe.
143139

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp