
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/client/2_automatic_node_discovery.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_client_2_automatic_node_discovery.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_client_2_automatic_node_discovery.py:


Automatic node discovery
========================

Showcases how the client automatically discovers nodes
and gets their description.

.. GENERATED FROM PYTHON SOURCE LINES 8-15

.. code-block:: Python


    from pyaseba.client import Client

    client = Client()
    connection = client.connect("tcp", port=33333)
    connection





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    1



.. GENERATED FROM PYTHON SOURCE LINES 16-19

The client regularly broadcasts a discovery message. Remote nodes that
answer are asked to send their description. The following method
waits until the descriptions are received.

.. GENERATED FROM PYTHON SOURCE LINES 19-22

.. code-block:: Python


    client.wait_nodes(wait_ms=500)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    {1: {0}}



.. GENERATED FROM PYTHON SOURCE LINES 23-24

Discovered node IDs are kept in memory

.. GENERATED FROM PYTHON SOURCE LINES 24-27

.. code-block:: Python


    client.node_ids





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    {1: {0}}



.. GENERATED FROM PYTHON SOURCE LINES 28-29

as well as their description.

.. GENERATED FROM PYTHON SOURCE LINES 29-32

.. code-block:: Python


    client.descriptions





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    {1: {0: Description(name='SimpleNode', protocol_version=9, variables={'_productId': (34, 1), 'args': (2, 32), 'counter': (35, 1), 'id': (0, 1), 'source': (1, 1), 'value': (36, 1)}, local_events={'event': 'emitted at each control step after incrementing counter'}, user_events={}, functions={'duplicate': ('duplicates the input', [('input', 1), ('result', 1)]), 'square': ('set value to the square of the input', [('input', 1)])})}}



.. GENERATED FROM PYTHON SOURCE LINES 33-35

Alternatively, if we wait for a single node, we
can call

.. GENERATED FROM PYTHON SOURCE LINES 35-39

.. code-block:: Python


    node_id, connection = client.wait_node(wait_ms=500)
    node_id, connection





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    (0, 1)



.. GENERATED FROM PYTHON SOURCE LINES 40-41

and

.. GENERATED FROM PYTHON SOURCE LINES 41-44

.. code-block:: Python


    client.get_description(node_id=node_id)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    Description(name='SimpleNode', protocol_version=9, variables={'_productId': (34, 1), 'args': (2, 32), 'counter': (35, 1), 'id': (0, 1), 'source': (1, 1), 'value': (36, 1)}, local_events={'event': 'emitted at each control step after incrementing counter'}, user_events={}, functions={'duplicate': ('duplicates the input', [('input', 1), ('result', 1)]), 'square': ('set value to the square of the input', [('input', 1)])})



.. GENERATED FROM PYTHON SOURCE LINES 45-46

.. code-block:: Python

    client.close()








.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 1.050 seconds)


.. _sphx_glr_download_gallery_client_2_automatic_node_discovery.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: 2_automatic_node_discovery.ipynb <2_automatic_node_discovery.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: 2_automatic_node_discovery.py <2_automatic_node_discovery.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: 2_automatic_node_discovery.zip <2_automatic_node_discovery.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
