Skip to content

Commit aac088e

Browse files
committed
0.9.3 Docs.
1 parent 0e67d71 commit aac088e

File tree

105 files changed

+19360
-2219
lines changed

Some content is hidden

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

105 files changed

+19360
-2219
lines changed
File renamed without changes.
File renamed without changes.

_images/ftp_uri.png

25 KB
Loading

_images/ftp_uri1.png

25 KB
Loading

_images/http_uri.png

20.2 KB
Loading

_images/http_uri1.png

20.2 KB
Loading

_images/mailto_uri.png

9.98 KB
Loading

_images/mailto_uri1.png

9.98 KB
Loading

_sources/atom_reader.txt

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
.. _atom_reader:
2+
3+
*************
4+
Atom 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+
The code
12+
========
13+
14+
.. code-block:: c++
15+
16+
#include "atom.hpp"
17+
#include <boost/network/protocol/http/client.hpp>
18+
#include <boost/foreach.hpp>
19+
#include <iostream>
20+
21+
int main(int argc, char * argv[]) {
22+
using namespace boost::network;
23+
24+
if (argc != 2) {
25+
std::cout << "Usage: " << argv[0] << " <url>" << std::endl;
26+
return 1;
27+
}
28+
29+
try {
30+
http::client client;
31+
http::client::request request(argv[1]);
32+
request << header("Connection", "close");
33+
http::client::response response = client.get(request);
34+
atom::feed feed(response);
35+
36+
std::cout << "Feed: " << feed.title()
37+
<< " (" << feed.subtitle() << ")" << std::endl;
38+
BOOST_FOREACH(const atom::entry &entry, feed) {
39+
std::cout << entry.title()
40+
<< " (" << entry.published() << ")" << std::endl;
41+
}
42+
}
43+
catch (std::exception &e) {
44+
std::cerr << e.what() << std::endl;
45+
}
46+
47+
return 0;
48+
}
49+
50+
Building and running ``atom_reader``
51+
====================================
52+
53+
.. code-block:: bash
54+
55+
$ cd ~/cpp-netlib-build
56+
$ make atom_reader
57+
58+
And to run the example from the command line to access the feed that
59+
lists of all the commits on cpp-netlib's master repository:
60+
61+
.. code-block:: bash
62+
63+
$ ./example/atom_reader https://github.com/cpp-netlib/cpp-netlib/commits/master.atom
64+
65+
Diving into the code
66+
====================
67+
68+
Most of this will now be familiar. The response is passed to the
69+
constructor to the ``atom::feed`` class, which parses the resultant
70+
XML. To keep this example as simple as possible, `rapidxml`_, a
71+
header-only XML parser library, was used to parse the response.
72+
73+
.. _`rapidxml`: http://rapidxml.sourceforge.net/
74+
75+
A similar example using RSS feeds exists in
76+
``libs/network/example/rss``.
File renamed without changes.

sources/examples.txt renamed to _sources/examples.txt

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ The :mod:`cpp-netlib` is a practical library that is designed to aid
55
the development of applications for that need to communicate using
66
common networking protocols. The following set of examples describe a
77
series of realistic examples that use the :mod:`cpp-netlib` for these
8-
kinds of application.
9-
10-
.. todo::
11-
12-
Make the examples more accessible.
8+
kinds of application. All examples are built using CMake.
139

1410
.. toctree::
1511
:maxdepth: 2
1612

1713
examples_http.rst
18-
.. examples_xmpp.rst
14+

sources/examples_http.txt renamed to _sources/examples_http.txt

+3
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ embedded into larger applications.
99
:maxdepth: 2
1010

1111
http_client.rst
12+
simple_wget.rst
1213
hello_world_server.rst
1314
hello_world_client.rst
15+
atom_reader.rst
16+
twitter_search.rst

_sources/getting_started.txt

+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
.. _getting_started:
2+
3+
*****************
4+
Getting Started
5+
*****************
6+
7+
Downloading an official release
8+
===============================
9+
10+
All stable versions of :mod:`cpp-netlib` can be downloaded from
11+
Github_ from this url:
12+
13+
http://github.com/cpp-netlib/cpp-netlib/downloads
14+
15+
Each release is available as gzipped (Using the command
16+
``tar xzf cpp-netlib.tar.gz``) or bzipped (Using ``tar xjf
17+
cpp-netlib.tar.bz2``) tarball, or as a zipfile (``unzip
18+
cpp-netlib.zip``, or on Windows using a tool such as 7zip_).
19+
20+
.. _Github: http://github.com/cpp-netlib/cpp-netlib/downloads
21+
.. _7zip: http://www.7-zip.org/
22+
23+
Downloading a development version
24+
=================================
25+
26+
The :mod:`cpp-netlib` uses Git_ for source control, so to use any
27+
development versions Git must be installed on your system.
28+
29+
Using the command line, the command to get the latest code is:
30+
31+
::
32+
33+
shell$ git clone git://github.com/mikhailberis/cpp-netlib.git
34+
35+
This should be enough information get to started. To do more complex
36+
things with Git, such as pulling changes or checking out a new branch,
37+
refer to the `Git documentation`_.
38+
39+
.. note:: If you look at the Git repository closely, this is the repository of
40+
*mikhailberis* instead of *cpp-netlib*. The reason is that the main developer
41+
and maintainer of the project is Dean Michael Berris, who goes by the alias
42+
*mikhailberis* on the Internet.
43+
44+
Dean does the merging and maintenance of the whole library, similar to how
45+
`Linus Torvalds`_ of the Linux project acts as the gatekeeper of the project.
46+
47+
.. _`Linus Torvalds`: http://en.wikipedia.org/wiki/Linus_Torvalds
48+
49+
Windows users need to use msysGit_, and to invoke the command above
50+
from a shell.
51+
52+
For fans of Subversion_, the same code can be checked out from
53+
http://svn.github.com/mikhailberis/cpp-netlib.git.
54+
55+
.. _Git: http://git-scm.com/
56+
.. _`Git documentation`: http://git-scm.com/documentation
57+
.. _msysGit: http://code.google.com/p/msysgit/downloads/list
58+
.. _Subversion: http://subversion.tigris.org/
59+
60+
.. note:: The :mod:`cpp-netlib` project is hosted on GitHub_ and follows the
61+
prescribed development model for GitHub_ based projects. This means in case
62+
you want to submit patches, you will have to create a fork of the project
63+
(read up on forking_) and then submit a pull request (read up on submitting
64+
`pull requests`_).
65+
66+
.. _forking: http://help.github.com/forking/
67+
.. _`pull requests`: http://help.github.com/pull-requests/
68+
69+
Getting Boost
70+
=============
71+
72+
:mod:`cpp-netlib` depends on Boost_. It should work for any version
73+
of Boost above 1.45.0. If Boost is not installed on your system, the
74+
latest package can be found on the `Boost web-site`_. The environment
75+
variable ``BOOST_ROOT`` must be defined, which must be the full path
76+
name of the top directory of the Boost distribution. Although Boost
77+
is mostly header only, applications built using :mod:`cpp-netlib`
78+
still requires linking with `Boost.System`_, `Boost.Date_time`_, and
79+
`Boost.Regex`_.
80+
81+
.. _Boost: http://www.boost.org/doc/libs/release/more/getting_started/index.html
82+
.. _`Boost web-site`: http://www.boost.org/users/download/
83+
.. _`Boost.System`: http://www.boost.org/libs/system/index.html
84+
.. _`Boost.Date_time`: http://www.boost.org/libs/date_time/index.html
85+
.. _`Boost.Regex`: http://www.boost.org/libs/regex/index.html
86+
87+
.. note:: You can follow the steps in the `Boost Getting Started`_ guide to
88+
install Boost into your development system.
89+
90+
.. _`Boost Getting Started`:
91+
http://www.boost.org/doc/libs/release/more/getting_started/index.html
92+
93+
.. warning:: There is a known incompatibility between :mod:`cpp-netlib` and
94+
Boost 1.46.1 on some compilers. It is not recommended to use :mod:`cpp-netlib`
95+
with Boost 1.46.1. Some have reported though that Boost 1.47.0
96+
and :mod:`cpp-netlib` work together better.
97+
98+
Getting CMake
99+
=============
100+
101+
The :mod:`cpp-netlib` uses CMake_ to generate platform-specific build files. If
102+
you intend to run the test suite, you can follow the instructions below.
103+
Otherwise, you don't need CMake to use :mod:`cpp-netlib` in your project. The
104+
:mod:`cpp-netlib` requires CMake version 2.8 or higher.
105+
106+
.. _CMake: http://www.cmake.org/
107+
108+
Let's assume that you have unpacked the :mod:`cpp-netlib` at the top of your
109+
HOME directory. On Unix-like systems you will typically be able to change into
110+
your HOME directory using the command ``cd ~``. This sample below assumes that
111+
the ``~/cpp-netlib`` directory exists, and is the top-level directory of the
112+
:mod:`cpp-netlib` release.
113+
114+
Building with CMake
115+
===================
116+
117+
To build the tests that come with cpp-netlib, we first need to configure the
118+
build system to use our compiler of choice. This is done by running the
119+
``cmake`` command at the top-level directory of :mod:`cpp-netlib` with
120+
additional parameters::
121+
122+
$ mkdir ~/cpp-netlib-build
123+
$ cd ~/cpp-netlib-build
124+
$ cmake -DCMAKE_BUILD_TYPE=Debug \
125+
> -DCMAKE_C_COMPILER=gcc \
126+
> -DCMAKE_CXX_COMPILER=g++ \
127+
> ../cpp-netlib
128+
129+
.. note:: While it's not compulsory, it's recommended that
130+
:mod:`cpp-netlib` is built outside the source directory.
131+
For the purposes of documentation, we'll assume that all
132+
builds are done in ``~/cpp-netlib-build``.
133+
134+
Building on Linux
135+
~~~~~~~~~~~~~~~~~
136+
137+
On Linux, this will generate the appropriate Makefiles that will enable you to
138+
build and run the tests and examples that come with :mod:`cpp-netlib`. To build
139+
the tests, you can run ``make`` in the same top-level directory of
140+
``~/cpp-netlib-build``::
141+
142+
$ make
143+
144+
.. note:: Just like with traditional GNU Make, you can add the ``-j`` parameter
145+
to specify how many parallel builds to run. In case you're in a sufficiently
146+
powerful system and would like to parallelize the build into 4 jobs, you can
147+
do this with::
148+
149+
make -j4
150+
151+
As a caveat, :mod:`cpp-netlib` is heavy on template metaprogramming and will
152+
require a lot of computing and memory resources to build the individual
153+
tests. Do this at the risk of thrashing_ your system. However, this
154+
compile-time burden is much reduced in recent versions.
155+
156+
.. _thrashing: http://en.wikipedia.org/wiki/Thrashing_(computer_science)
157+
158+
Once the build has completed, you can now run the test suite by issuing::
159+
160+
$ make test
161+
162+
Building On Windows
163+
~~~~~~~~~~~~~~~~~~~
164+
165+
If you're using the Microsoft Visual C++ compiler or the Microsoft Visual Studio
166+
IDE and you would like to build cpp-netlib from within Visual Studio, you can
167+
look for the solution and project files as the artifacts of the call to
168+
``cmake`` -- the file should be named ``CPP-NETLIB.sln`` (the solution) along
169+
with a number of project files for Visual Studio.
170+
171+
.. note:: As of version 0.9.3, :mod:`cpp-netlib` produces three static
172+
libraries. Using GCC on Linux these are::
173+
174+
libcppnetlib-client-connections.a
175+
libcppnetlib-server-parsers.a
176+
libcppnetlib-uri.a
177+
178+
And using Visual C++ on Windows they are::
179+
180+
cppnetlib-client-connections.lib
181+
cppnetlib-server-parsers.lib
182+
cppnetlib-uri.lib
183+
184+
Users can find them in ``~/cpp-netlib-build/libs/network/src``.
185+
186+
Reporting Issues, Getting Support
187+
=================================
188+
189+
In case you find yourself stuck or if you've found a bug (or you want to just
190+
join the discussion) you have a few options to choose from.
191+
192+
For reporting bugs, feature requests, and asking questions about the
193+
implementation and/or the documentation, you can go to the GitHub issues page
194+
for the project at http://github.com/cpp-netlib/cpp-netlib/issues.
195+
196+
You can also opt to join the developers mailing list for a more personal
197+
interaction with the developers of the project. You can join the mailing list
198+
through http://groups.google.com/forum/#!forum/cpp-netlib.
199+

_sources/hello_world_client.txt

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
.. _hello_world_http_client:
2+
3+
***************************
4+
"Hello world" HTTP client
5+
***************************
6+
7+
Since we have a "Hello World" HTTP server, let's then create an HTTP client to
8+
access that server. This client will be similar to the HTTP client we made
9+
earlier in the documentation.
10+
11+
The code
12+
========
13+
14+
We want to create a simple HTTP client that just makes a request to the HTTP
15+
server that we created earlier. This really simple client will look like this:
16+
17+
.. code-block:: c++
18+
19+
#include <boost/network/protocol/http/client.hpp>
20+
#include <string>
21+
#include <sstream>
22+
#include <iostream>
23+
24+
namespace http = boost::network::http;
25+
26+
int main(int argc, char * argv[]) {
27+
if (argc != 3) {
28+
std::cerr << "Usage: " << argv[0] << " address port" << std::endl;
29+
return 1;
30+
}
31+
32+
try {
33+
http::client client;
34+
std::ostringstream url;
35+
url << "http://" << argv[1] << ":" << argv[2] << "/";
36+
http::client::request request(url.str());
37+
http::client::response response =
38+
client.get(request);
39+
std::cout << body(response) << std::endl;
40+
} catch (std::exception & e) {
41+
std::cerr << e.what() << std::endl;
42+
return 1;
43+
}
44+
return 0;
45+
}
46+
47+
Building and running the client
48+
===============================
49+
50+
Just like with the HTTP Server and HTTP client example before, we can build this
51+
example by doing the following on the shell:
52+
53+
.. code-block:: bash
54+
55+
$ cd ~/cpp-netlib-build
56+
$ make hello_world_client
57+
58+
This example can be run from the command line as follows:
59+
60+
.. code-block:: bash
61+
62+
$ ./example/hello_world_client http://127.0.0.1:8000
63+
64+
.. note:: This assumes that you have the ``hello_world_server`` running on
65+
localhost port 8000.
66+
67+
Diving into the code
68+
====================
69+
70+
All this example shows is how easy it is to write an HTTP client that connects
71+
to an HTTP server, and gets the body of the response. The relevant lines are:
72+
73+
.. code-block:: c++
74+
75+
http::client client;
76+
http::client::request request(url.str());
77+
http::client::response response =
78+
client.get(request);
79+
std::cout << body(response) << std::endl;
80+
81+
You can then imagine using this in an XML-RPC client, where you can craft the
82+
XML-RPC request as payload which you can pass as the body to a request, then
83+
perform the request via HTTP:
84+
85+
.. code-block:: c++
86+
87+
http::client client;
88+
http::client::request request("http://my.webservice.com/");
89+
http::client::response =
90+
client.post(request, "application/xml", some_xml_string);
91+
std::data = body(response);
92+
93+
The next set of examples show some more practical applications using
94+
the :mod:`cpp-netlib` HTTP client.

0 commit comments

Comments
 (0)