TcpClient#
- class lsst.ts.m2com.TcpClient(host: str, port: int, callback_process_message: Callable[[...], Coroutine], *args: Any, log: Logger | None = None, sequence_generator: Generator | None = None, name: str = 'tcp-client', check_message_rate: bool = False)#
Bases:
ClientTCP/IP client.
Parameters#
- host
str Host address.
- port
int Port to connect.
- callback_process_message
coroutine Function to process the received message. It must has a keyward argument of “message” to receive the message as a dictionary.
- *args
args Arguments needed in “callback_process_message” function call.
- log
logging.Loggeror None, optional A logger. If None, a logger will be instantiated. (the default is None)
- sequence_generator
generatororNone, optional Sequence generator. (the default is None)
- name
str, optional Name of the tcp-client. Used for logging/debugging purposes. The default is “tcp-client”)
- check_message_rate
bool, optional Check the message rate or not. If True, the rate of message will be calculated and recorded in the debug logging message. (the default is False)
Attributes#
- log
logging.Logger A logger.
- timeout
float Read timeout in second.
- last_sequence_id
int Last sequence ID of command.
Methods Summary
close()Cancel the task and close the connection.
connect([timeout])Connect to the server.
write_message(msg_type, msg_name[, ...])Writes message to the server.
Methods Documentation
- async close() None#
Cancel the task and close the connection.
Note: this function is safe to call even though there is no connection.
- async connect(timeout: float = 10.0) None#
Connect to the server.
Parameters#
- timeout
float, optional Timeout in second. (default is 10.0)
- timeout
- async write_message(msg_type: MsgType, msg_name: str, msg_details: dict | None = None, comp_name: str | None = None) None#
Writes message to the server.
Parameters#
- msg_typeenum
MsgType Message type.
- msg_name
str Message name.
- msg_details
dictor None, optional Message details. (the default is None)
- comp_name
stror None, optional Specific component name used in the event or telemetry. (the default is None)
Raises#
- RuntimeError
When there is no TCP/IP connection.
- ValueError
If ‘id’ is in the message details already.
- ValueError
When the message type is not supported.
- msg_typeenum
- host