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:
- host
str
Host address.
- port
int
Port to connect.
- timeout_in_second
float
, optional Read timeout in second. (the default is 0.05)
- log
logging.Logger
or None, optional A logger. If None, a logger will be instantiated. (the default is None)
- sequence_generator
generator
orNone
, optional Sequence generator. (the default is None)
- maxsize_queue
int
, optional Maximum size of queue. (the default is 1000)
- name
str
, optional Name of the tcp-client. Used for logging/debugging purposes.
- host
- Attributes:
- host
str
Host address.
- port
int
Port to connect.
- name
str
Name of the tcp-client.
- log
logging.Logger
A logger.
- reader
asyncio.StreamReader
or None Reader of socker.
- writer
asyncio.StreamWriter
or None Writer of the socket.
- timeout
float
Read timeout in second.
- last_sequence_id
int
Last sequence ID of command.
- queue
asyncio.Queue
Queue of the message.
- queue_full_log_interval
float
When queue is full, how long to wait until logging condition again (in seconds)?
- queue_full_messages_lost
int
How many messages were lost while queue was full.
- host
Methods Summary
close
()Cancel the task and close the connection.
connect
([connect_retry_interval, timeout])Connect to the server.
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:
- 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:
- 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.