set demos as console scripts, update chat instructions

This commit is contained in:
pacrob
2024-12-20 13:23:04 -07:00
committed by Paul Robinson
parent bc90632f9d
commit a72dbaa58d
9 changed files with 77 additions and 38 deletions

View File

@ -1,18 +1,33 @@
Chat Demo
=========
Copy the code below into a file called ``chat.py``.
Install dependencies, preferably in a virtual environment, with:
This example demonstrates how to create a simple chat application using libp2p.
.. code-block:: bash
.. code-block:: console
python -m pip install libp2p
$ python -m pip install libp2p
Collecting libp2p
...
Successfully installed libp2p-x.x.x
$ chat-demo
Run this from the same folder in another console:
chat-demo -p 8001 -d /ip4/127.0.0.1/tcp/8000/p2p/QmPouApKqyxJDy6YT21EXNS6efuNzvJ3W3kqRQxkQ77GFJ
Run the demo with ``python chat.py`` and copy the output.
Waiting for incoming connection...
Open a second terminal, navigate to the folder that contains ``chat.py``, then paste
and run the copied line.
Copy the line that starts with ``chat-demo -p 8001``, open a new terminal in the same
folder and paste it in:
.. code-block:: console
$ chat-demo -p 8001 -d /ip4/127.0.0.1/tcp/8000/p2p/QmPouApKqyxJDy6YT21EXNS6efuNzvJ3W3kqRQxkQ77GFJ
Connected to peer /ip4/127.0.0.1/tcp/8000
You can then start typing messages in either terminal and see them relayed to the
other terminal. To exit the demo, send a keyboard interrupt (``Ctrl+C``) in either terminal.
The full source code for this example is below:
.. literalinclude:: ../examples/chat/chat.py
:language: python