mxcubecore.ipc.transports.jsonrpc_tcp

JSON-RPC 2.0 over a raw, newline-delimited TCP socket, optionally TLS.

Built on gevent.server.StreamServer to match the gevent-based concurrency model as we are using (PyDispatcher/gevent).

Classes

JSONRPCTCPTransport(host, port[, ...])

Single-client JSON-RPC/TCP transport.

class mxcubecore.ipc.transports.jsonrpc_tcp.JSONRPCTCPTransport(host: str, port: int, tls_cert_path: str | None = None, tls_key_path: str | None = None)[source]

Bases: Transport

Single-client JSON-RPC/TCP transport.

Parameters:
  • host (str)

  • port (int)

  • tls_cert_path (str | None)

  • tls_key_path (str | None)

property address

The actual bound (host, port).

bind(session_id: str) → None[source]

Called by IPCServer once session_id has authenticated.

Transports that can’t tell clients apart by connection (NanoMQ) use this to reserve the single client slot.

Parameters:

session_id (str)

Return type:

None

has_active_client() → bool[source]

Whether a client is currently connected.

Return type:

bool

send(session_id: str, raw_json: str) → None[source]

Send one frame to the given session, if it is still connected.

Parameters:
  • session_id (str)

  • raw_json (str)

Return type:

None

start(on_message: Callable[[str, str], None], on_connect: Callable[[str], None], on_disconnect: Callable[[str], None]) → None[source]

Start listening for (or connecting to) clients.

on_message(session_id, raw_json) is called for every inbound frame.

on_disconnect(session_id) when a client’s connection is torn down at the transport level

on_connect(session_id, peer) is called when a connection is established; peer is a human-readable “ip:port (hostname)” string for transports that have one (JSON-RPC/TCP), or None for transports that don’t (NanoMQ has no per-connection socket only a _client_id in each message).

Parameters:
Return type:

None

stop() → None[source]

Stop the transport and release any resources (sockets, MQTT client loop etc.).

Return type:

None