TcpClient

class lsst.ts.m2com.TcpClient(host, port, timeout_in_second=0.05, log=None, sequence_generator=None, maxsize_queue=1000, name='tcp-client')

Bases: object

TCP/IP client.

Parameters:
hoststr

Host address.

portint

Port to connect.

timeout_in_secondfloat, optional

Read timeout in second. (the default is 0.05)

loglogging.Logger or None, optional

A logger. If None, a logger will be instantiated. (the default is None)

sequence_generatorgenerator or None, optional

Sequence generator. (the default is None)

maxsize_queueint, optional

Maximum size of queue. (the default is 1000)

namestr, optional

Name of the tcp-client. Used for logging/debugging purposes.

Attributes:
hoststr

Host address.

portint

Port to connect.

namestr

Name of the tcp-client.

loglogging.Logger

A logger.

readerasyncio.StreamReader or None

Reader of socker.

writerasyncio.StreamWriter or None

Writer of the socket.

timeoutfloat

Read timeout in second.

last_sequence_idint

Last sequence ID of command.

queueasyncio.Queue

Queue of the message.

queue_full_log_intervalfloat

When queue is full, how long to wait until logging condition again (in seconds)?

queue_full_messages_lostint

How many messages were lost while queue was full.

Methods Summary

close()

Cancel the task and close the connection.

connect([connect_retry_interval, timeout])

Connect to the server.

is_connected()

Determines if the client is connected to the server.

write(msg_type, msg_name[, msg_details, ...])

Writes message to the server.

Methods Documentation

async close()

Cancel the task and close the connection.

Note: this function is safe to call even though there is no connection.

async connect(connect_retry_interval=1.0, timeout=10.0)

Connect to the server.

Parameters:
connect_retry_intervalfloat, optional

How long to wait before trying to reconnect when connection fails. (default is 1.0)

timeoutfloat, optional

Timeout in second. This value should be larger than the connect_retry_interval. (default is 10.0)

Raises:
asyncio.TimeoutError

Connection timeout in the timeout period.

is_connected()

Determines if the client is connected to the server.

Returns:
bool

True if is connected. Else, False.

async write(msg_type, msg_name, msg_details=None, comp_name=None)

Writes message to the server.

Parameters:
msg_typeMsgType

Message type.

msg_namestr

Message name.

msg_detailsdict or None, optional

Message details. (the default is None)

comp_namestr or 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.