bpod_core.ipc.ServiceClient

class bpod_core.ipc.ServiceClient

Bases: ServiceBase, Generic[U]

A client for communicating with ServiceHost.

__init__(service_type, address=None, event_handler=None, discovery_timeout=10.0, txt_properties=None, default_data_type=None, *, remote=True) None

Initialize a ServiceClient instance.

Parameters:
  • service_type (str) – The service type to discover or connect to.

  • address (str, optional) – The direct connection address for the REQ channel, by default None.

  • event_handler (callable, optional) – A callback to handle PUB messages, by default None.

  • discovery_timeout (float, optional) – Timeout in seconds for service discovery, by default 10.0.

  • txt_properties (dict, optional) – Properties for service filtering during discovery, by default None.

  • default_data_type (type, optional) – The default data type for incoming messages.

  • remote (bool, optional) – Whether to use Zeroconf for discovering remote services, by default True.

Return type:

None

close() None

Close the client and clean up resources.

Return type:

None

request(request_data, reply_type=None) Any

Send a generic request to the server.

Parameters:
  • request_data (Any) – The request payload.

  • reply_type (type, optional) – Override the expected reply type.

Returns:

The reply data from the server.

Return type:

U or T

Raises:
  • RemoteError – If an error occurred on the host side.

  • ServiceError – If the host sent an unexpected reply kind.

property address_req: str

The address for the REQ channel.

property address_sub: str

The address for the SUB channel.

is_local: bool

Whether the client is connected to a service on localhost.