bpod_core.ipc.ServiceHost

class bpod_core.ipc.ServiceHost

Bases: ServiceBase

A ZeroMQ host providing REQ/REP and PUB/SUB sockets with service discovery.

Provides two communication channels: a REQ/REP channel for synchronous request-reply messaging and a PUB/SUB channel for broadcasting events to subscribers. Incoming requests are dispatched to a user-provided event_handler callback.

The service is automatically advertised for discovery by ServiceClient. It is advertised locally via a file in the user’s runtime directory for inter-process communication. When remote=True, the service is additionally advertised via Zeroconf (mDNS) for network-wide discovery and remote-process communication.

__init__(service_name, service_type, properties=None, event_handler=None, port_pub=None, port_rep=None, serialization='msgpack', *, remote=True) None

Initialize the ServiceHost.

Parameters:
  • service_name (str) – Service name to advertise.

  • service_type (str) – Service type.

  • properties (dict, optional) – Additional properties for service advertisement.

  • event_handler (callable, optional) – Function to handle incoming requests.

  • port_pub (int, optional) – TCP port to bind the PUB socket. If None, a random available port is chosen.

  • port_rep (int, optional) – TCP port to bind the REP socket. If None, a random available port is chosen.

  • serialization (str, default 'msgpack') – Serialization format for message encoding.

  • remote (bool, default True) – If True, binds TCP sockets to ‘0.0.0.0’. Otherwise, binds to ‘127.0.0.1’.

Return type:

None

close() None

Close the host and clean up resources.

Return type:

None