Skip to content

Commit

Permalink
update echo and ping example docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pacrob committed Jan 1, 2025
1 parent 4c32c0c commit 83467be
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
29 changes: 22 additions & 7 deletions docs/examples.echo.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
Echo Demo
=========

Copy the code below into a file called ``demo.py``.
Install dependencies, preferably in a virtual environment, with:
This example demonstrates a simple ``echo`` protocol.

.. code-block:: bash
.. code-block:: console
python -m pip install libp2p
$ python -m pip install libp2p
Collecting libp2p
...
Successfully installed libp2p-x.x.x
$ echo-demo
Run this from the same folder in another console:
Run the demo with ``python echo.py`` and copy the output.
echo-demo -p 8001 -d /ip4/127.0.0.1/tcp/8000/p2p/16Uiu2HAmAsbxRR1HiGJRNVPQLNMeNsBCsXT3rDjoYBQzgzNpM5mJ
Open a second terminal, navigate to the folder that contains ``echo.py``, then paste
and run the copied line.
Waiting for incoming connection...
Copy the line that starts with ``echo-demo -p 8001``, open a new terminal in the same
folder and paste it in:

.. code-block:: console
$ echo-demo -p 8001 -d /ip4/127.0.0.1/tcp/8000/p2p/16Uiu2HAmAsbxRR1HiGJRNVPQLNMeNsBCsXT3rDjoYBQzgzNpM5mJ
I am 16Uiu2HAmE3N7KauPTmHddYPsbMcBp2C6XAmprELX3YcFEN9iXiBu
Sent: hi, there!
Got: hi, there!
.. literalinclude:: ../examples/echo/echo.py
:language: python
Expand Down
28 changes: 21 additions & 7 deletions docs/examples.ping.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
Ping Demo
=========

Copy the code below into a file called ``ping.py``.
Install dependencies, preferably in a virtual environment, with:
This example demonstrates how to use the libp2p ``ping`` protocol.

.. code-block:: bash
.. code-block:: console
python -m pip install libp2p
$ python -m pip install libp2p
Collecting libp2p
...
Successfully installed libp2p-x.x.x
$ ping-demo
Run this from the same folder in another console:
Run the demo with ``python ping.py`` and copy the output.
ping-demo -p 8001 -d /ip4/127.0.0.1/tcp/8000/p2p/QmXfptdHU6hqG95JswxYVUH4bphcK8y18mhFcgUQFe6fCN
Open a second terminal, navigate to the folder that contains ``ping.py``, then paste
and run the copied line.
Waiting for incoming connection...
Copy the line that starts with ``ping-demo -p 8001``, open a new terminal in the same
folder and paste it in:

.. code-block:: console
$ ping-demo -p 8001 -d /ip4/127.0.0.1/tcp/8000/p2p/QmXfptdHU6hqG95JswxYVUH4bphcK8y18mhFcgUQFe6fCN
sending ping to QmXfptdHU6hqG95JswxYVUH4bphcK8y18mhFcgUQFe6fCN
received pong from QmXfptdHU6hqG95JswxYVUH4bphcK8y18mhFcgUQFe6fCN
The full source code for this example is below:

.. literalinclude:: ../examples/echo/echo.py
:language: python
Expand Down

0 comments on commit 83467be

Please sign in to comment.