PublishClient#

class wattson.cosimulation.control.interface.publish_client.PublishClient(socket_string: str, namespace: Namespace | None = None, on_receive_notification_callback: Callable[[WattsonNotification], None] | None = None)#

Bases: Thread

Represents a thread-based client for receiving and processing notifications from the Wattson CoSimulationController.

Important

This class is usually only used by the WattsonClient and should not be instantiated directly.

Methods

__init__

Initializes a new instance of the PublishClient.

run

Runs the publish client in a dedicated thread.

set_on_receive_notification_callback

Sets the callback to be called for each received notification.

set_registration

start

Starts the client and connects to the CoSimulationController.

stop

Gracefully stops the client and waits for it to terminate.

__init__(socket_string: str, namespace: Namespace | None = None, on_receive_notification_callback: Callable[[WattsonNotification], None] | None = None)#

Initializes a new instance of the PublishClient.

Parameters:
  • socket_string (str) – The full socket string to use for the connection (e.g., tcp://127.0.0.1:5555).

  • namespace (Optional[Namespace], optional) – Optionally, a Namespace instance to use for communicating from outside the simulation. (Default value = None)

  • on_receive_notification_callback (Optional[Callable[[WattsonNotification], None]], optional) – The callback to be called for each received notification. (Default value = None)

run() None#

Runs the publish client in a dedicated thread. This method handles the connection, passes notifications to the respective handlers and waits for the termination request.

Important

This method is automatically called by the start() method and may not be run directly.

set_on_receive_notification_callback(callback: Callable[[WattsonNotification], None])#

Sets the callback to be called for each received notification.

Parameters:

callback (Callable[[WattsonNotification], None]) – The callback to be called for each received notification. The received notification is passed to the callback as an argument.

start() None#

Starts the client and connects to the CoSimulationController.

stop(timeout: float | None = None)#

Gracefully stops the client and waits for it to terminate.

Parameters:

timeout (Optional[float], optional) – An optional timeout in seconds to wait for termination. If not specified, the method will wait indefinitely. (Default value = None)