plestylib.service.tcp_ip_server
===============================

.. py:module:: plestylib.service.tcp_ip_server


Classes
-------

.. autoapisummary::

   plestylib.service.tcp_ip_server.DeviceTCPIPServer


Module Contents
---------------

.. py:class:: DeviceTCPIPServer(device, wrapper_cls, address='tcp://*:5555')

   ZeroMQ-based asynchronous device server.

   This server exposes a synchronous device over TCP/IP using a JSON-based
   RPC protocol. The device is wrapped using an async wrapper (e.g.,
   AsyncWrapperSafe or AsyncDeviceThread) to ensure safe, serialized access.

   The server supports multiple concurrent clients via a ROUTER socket.

   Protocol:

   Request payload:

   .. code-block:: json

       {
         "type": "query | write | call | help | describe",
         "timeout": 3.0
       }

   Response payload:

   .. code-block:: json

       {"status": "ok", "result": "..."}

   Error response payload:

   .. code-block:: json

       {"status": "error", "error": "message", "type": "ExceptionType"}

   Initialize the device server.

   :param device: Synchronous device instance.
   :param wrapper_cls: Async wrapper class (e.g., AsyncDeviceThread).
   :param address: ZMQ bind address.


   .. py:attribute:: device


   .. py:attribute:: ctx


   .. py:attribute:: socket


   .. py:property:: address

      Get the server's bind address.


   .. py:property:: is_running

      Check if the server is currently running.


   .. py:method:: _execute(coro, timeout=None)
      :async:


      Execute a coroutine with optional timeout.

      :param coro: Coroutine to execute.
      :param timeout: Timeout in seconds.

      :returns: Result of coroutine.

      :raises asyncio.TimeoutError: If timeout is exceeded.



   .. py:method:: _handle(request_str)
      :async:


      Handle a single client request.

      :param request_str: JSON-encoded request string.

      :returns: JSON-serializable response.
      :rtype: dict



   .. py:method:: _describe()
      :async:


      Introspect the device and list available methods.

      :returns: Available callable methods.
      :rtype: dict



   .. py:method:: _help()
      :async:



   .. py:method:: run()
      :async:


      Run the server loop indefinitely.

      This method listens for incoming requests and processes them
      sequentially. Each request is handled asynchronously.



   .. py:method:: shutdown()
      :async:


      Gracefully shutdown the server.



