pymasep.communication.base_threaded_communication

Classes

BaseThreadedCommunication

Base class for threaded communication for Client and Server

Module Contents

class pymasep.communication.base_threaded_communication.BaseThreadedCommunication(ident, socket_handler_class, socket_handler_args, host, port, log_level)

Base class for threaded communication for Client and Server

Parameters:
  • ident (str) – string id of the client or server.

  • host (str) – Host to listen or connect.

  • port (int) – Port to listen or connect.

  • socket_handler_class (Type[Any]) – Class used to handle the socket (send, receive).

  • socket_handler_args (tuple) – Arguments as tuple to instantiate the SocketHandler class.

  • log_level (Union[str, int]) – Log level messages to log as str or int. Default is logging.WARNING.

id

id of the communication thread

host

host to listen or connect

port

port to listen or connect

socket

socket used to listen or connect

logger: logging.Logger

communication logger

socket_handler_class

class to handle message from/to socket

socket_handler_args

socket handler arguments

_current_connections

keep trace of current connections

_current_connections_lock

lock to handle multiple connections at the same time

add_connection(ident, sh)

Add a connection to the client or server

Parameters:
  • ident (str) – ID of the opposite BaseThreadCommunication connected to self.

  • sh – Instance of the socket handler used to handle this connection

Return type:

None

get_connection(ident)

Get the socket handler of the connection

Parameters:

ident – ID of the connection

Returns:

the socket handler

is_connection_registered(ident)

Check if a connection is registered in this BaseThreadCommunication.

Parameters:

ident – ID of the connection

Returns:

True if a socket handler is associated to this connection id

send_frame_to(ident, frame)

Send a frame to a connection identified by ident

Parameters:
  • ident (str) – ID of the connection to send a frame.

  • frame – Frame to send.