pyrtma.web_manager.Client

class Client(module_id=0, host_id=0, timecode=False)[source]

Bases: object

RTMA Client interface

Parameters:
  • module_id (optional) – Static module ID, which must be unique. Defaults to 0, which generates a dynamic module ID.

  • host_id (optional) – Host ID. Defaults to 0.

  • timecode (optional) – Add additional timecode fields to message header, used by some projects at RNEL. Defaults to False.

Methods

connect

Connect to message manager server

discard_messages

Read and discard messages in socket buffer up to timeout

disconnect

Disconnect from message manager server

forward_message

Forward a message

pause_all_subscriptions

Pause all subscribed types

pause_subscription

Pause subscription to message types

paused_subscription_context

Context manager to pause subscriptions to a list of message types

read_message

Read a message

resume_all_subscriptions

Resume all paused subscriptions

resume_subscription

Resume subscription to message types

send_message

Send a message

send_module_ready

Send a signal to message manager that client is ready

send_signal

Send a signal

subscribe

Subscribe to message types

subscription_context

Context manager to subscribe to a list of message types

unsubscribe

Unsubscribe from message types

unsubscribe_from_all

Unsubscribe from all subscribed types

Attributes

connected

Status of connection to message manager server

header_cls

Class defining the RTMA message header

ip_addr

Message manager IP address string

module_id

Numeric module ID of client

msg_count

Count of messages that have been sent

paused_subscribed_types

Subscriptions on pause

port

Message manager port number

server

Message manager server address as a (IP_addr, port_num) tuple

sock

Underlying socket connection with MessageManager

subscribed_types

List of subscribed message types

connect(server_name='localhost:7111', logger_status=False, daemon_status=False)[source]

Connect to message manager server

Parameters:
  • server_name (optional) – IP_addr:port_num string associated with message manager. Defaults to “localhost:7111”.

  • logger_status (optional) – Flag to declare client as a logger module. Logger modules are automatically subscribed to all message types. Defaults to False.

  • daemon_status (optional) – Flag to declare client as a daemon. Defaults to False.

Raises:

MessageManagerNotFound – Unable to connect to message manager

property connected: bool

Status of connection to message manager server

discard_messages(timeout=1)[source]

Read and discard messages in socket buffer up to timeout

Parameters:

timeout (optional) – Maximum time in seconds to loop through message buffer. Defaults to 1.

Return type:

bool

Returns:

True if all messages have been read, False if messages remain in buffer

disconnect()[source]

Disconnect from message manager server

forward_message(msg_hdr, msg_data=None, timeout=-1)[source]

Forward a message

A message is a packet that contains a defined data payload. To send a message without associated data, see send_signal().

Parameters:
  • msg_hdr (MessageHeader) – Object containing RTMA header to send

  • msg_data (Optional[MessageData]) – Object containing the message to send

  • timeout (optional) – Timeout in seconds to wait for socket to be available for sending. Defaults to -1 (blocking).

property header_cls: Type[MessageHeader]

Class defining the RTMA message header

property ip_addr: str

Message manager IP address string

property module_id: int

Numeric module ID of client

property msg_count: int

Count of messages that have been sent

pause_all_subscriptions()[source]

Pause all subscribed types

pause_subscription(msg_list)[source]

Pause subscription to message types

Parameters:

msg_list (Iterable[int]) – A list of numeric message IDs to temporarily unsubscribe to

property paused_subscribed_types: Set[int]

Subscriptions on pause

paused_subscription_context(msg_list)[source]

Context manager to pause subscriptions to a list of message types

Message types will automatically resume subscriptions after exiting context.

Parameters:

msg_list (Iterable[int]) – A list of numeric message IDs to temporarily unsubscribe to

property port: int

Message manager port number

read_message(timeout=-1, ack=False, sync_check=False)[source]

Read a message

Parameters:
  • timeout (optional) – Timeout to wait for a message to be available for reading. Defaults to -1 (blocking).

  • ack (optional) – Primarily for internal use. When True, will not discard ACK messages. Defaults to False.

  • sync_check (optional) – Validate message definition matches header version. Defaults to False.

Raises:

ConnectionLost – Connection error to message manager server

Return type:

Optional[Message]

Returns:

Message object. If no message is read before timeout, returns None.

resume_all_subscriptions()[source]

Resume all paused subscriptions

resume_subscription(msg_list)[source]

Resume subscription to message types

Parameters:

msg_list (Iterable[int]) – A list of paused message IDs to resubscribe to

send_message(msg_data, dest_mod_id=0, dest_host_id=0, timeout=-1)[source]

Send a message

A message is a packet that contains a defined data payload. To send a message without associated data, see send_signal().

Parameters:
  • msg_data (MessageData) – Object containing the message to send

  • dest_mod_id (optional) – Specific module ID to send to. Defaults to 0 (broadcast).

  • dest_host_id (optional) – Specific host ID to send to. Defaults to 0 (broadcast).

  • timeout (optional) – Timeout in seconds to wait for socket to be available for sending. Defaults to -1 (blocking).

Raises:
send_module_ready()[source]

Send a signal to message manager that client is ready

This method also sends the client’s process ID to message manager.

send_signal(signal_type, dest_mod_id=0, dest_host_id=0, timeout=-1)[source]

Send a signal

A signal is a message type without an associated data payload. Only a unique message type ID is required to send a signal. To send a message with data, see send_message().

Parameters:
  • signal_type (int) – Numeric message type ID of signal

  • dest_mod_id (optional) – Specific module ID to send to. Defaults to 0 (broadcast).

  • dest_host_id (optional) – Specific host ID to send to. Defaults to 0 (broadcast).

  • timeout (optional) – Timeout in seconds to wait for socket to be available for sending. Defaults to -1 (blocking).

Raises:
property server: Tuple[str, int]

Message manager server address as a (IP_addr, port_num) tuple

property sock: socket

Underlying socket connection with MessageManager

subscribe(msg_list)[source]

Subscribe to message types

Calling this method multiple times will add to, and not replace, the list of subscribed messages.

Parameters:

msg_list (Iterable[int]) – A list of numeric message IDs to subscribe to

property subscribed_types: Set[int]

List of subscribed message types

subscription_context(msg_list)[source]

Context manager to subscribe to a list of message types

Message types will automatically unsubscribe after exiting context.

Parameters:

msg_list (Iterable[int]) – A list of numeric message IDs to subscribe to

unsubscribe(msg_list)[source]

Unsubscribe from message types

Parameters:

msg_list (Iterable[int]) – A list of numeric message IDs to unsubscribe to

unsubscribe_from_all()[source]

Unsubscribe from all subscribed types