Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -836,19 +836,25 @@ Networking with Trio
Now let's take what we've learned and use it to do some I/O, which is
where async/await really shines.


An echo client
~~~~~~~~~~~~~~

The traditional application for demonstrating network APIs is an "echo
server": a program that accepts arbitrary data from a client, and then
sends that same data right back. (Probably a more relevant example
The traditional toy application for demonstrating network APIs is an
"echo server": a program that awaits arbitrary data from remote clients,
and then sends that same data right back. (Probably a more relevant example
these days would be an application that does lots of concurrent HTTP
requests, but for that `you need an HTTP library
<https://github.com/python-trio/trio/issues/236#issuecomment-310784001>`__
such as `asks <https://asks.readthedocs.io>`__, so we'll stick
with the echo server tradition.)

In this tutorial, we present both ends of the pipe: the client, and the
server. The client periodically sends data to the server, and displays its
answers. The server awaits connections; when a client connects, it recopies
the received data back on the pipe.


An echo client
~~~~~~~~~~~~~~


To start with, here's an example echo *client*, i.e., the program that
will send some data at our echo server and get responses back:

Expand All @@ -857,6 +863,9 @@ will send some data at our echo server and get responses back:
.. literalinclude:: tutorial/echo-client.py
:linenos:

Note that this code will not work without a TCP server such as the one
we'll implement below.

The overall structure here should be familiar, because it's just like
our :ref:`last example <tutorial-example-tasks-intro>`: we have a
parent task, which spawns two child tasks to do the actual work, and
Expand Down