Utils
This module provides a socket server and client for managing connections in a distributed system.
ATTRIBUTE | DESCRIPTION |
---|---|
BYTE_SIZE |
size of the byte.
TYPE:
|
CLASS | DESCRIPTION |
---|---|
SocketServer |
Class for handling socket server operations. |
SocketClient |
Class for handling socket client operations. |
FUNCTION | DESCRIPTION |
---|---|
create_listen_socket_callback |
Create a callback function for listening to socket data. |
create_socket_user |
Create a Socket client instance. |
create_socket_worker |
Create a Socket worker instance. |
create_socket_hub |
Create a Socket hub instance. |
Documentation last updated: 2025-06-11
SocketClient
start_client
staticmethod
start_client(
host: str,
port: int,
controller: Controller,
relay: bool = False,
*,
terminate: Event | None = None,
)
Starts the client
PARAMETER | DESCRIPTION |
---|---|
host
|
the host
TYPE:
|
port
|
the port
TYPE:
|
controller
|
the controller
TYPE:
|
relay
|
flag to indicate relay. Defaults to False.
TYPE:
|
terminate
|
the termination event. Defaults to None.
TYPE:
|
SocketServer
handle_client
staticmethod
handle_client(
client_socket: socket,
client_addr: str,
controller: Controller,
client_role: str | None = None,
*,
terminate: Event | None = None,
)
Handles communication with a single client
PARAMETER | DESCRIPTION |
---|---|
client_socket
|
the client socket
TYPE:
|
client_addr
|
the client address
TYPE:
|
controller
|
the controller
TYPE:
|
client_role
|
the client role. Defaults to None.
TYPE:
|
terminate
|
the termination event. Defaults to None.
TYPE:
|
start_server
staticmethod
start_server(
host: str,
port: int,
controller: Controller,
*,
n_connections: int = 5,
terminate: Event | None = None,
)
Starts the server
PARAMETER | DESCRIPTION |
---|---|
host
|
the host
TYPE:
|
port
|
the port
TYPE:
|
controller
|
the controller
TYPE:
|
n_connections
|
the number of connections. Defaults to 5.
TYPE:
|
terminate
|
the termination event. Defaults to None
TYPE:
|
create_listen_socket_callback
Create a callback function for listening to socket data.
PARAMETER | DESCRIPTION |
---|---|
client_socket
|
the client socket
TYPE:
|
relay
|
flag to indicate if the socket is a relay
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable[[Any], str]
|
Callable[[Any], str]: a function that listens for incoming data on the socket |
create_socket_hub
create_socket_hub(
host: str,
port: int,
address: str | None = None,
relay: bool = True,
) -> tuple[Controller, dict[str, Any]]
Create a Socket client instance.
PARAMETER | DESCRIPTION |
---|---|
host
|
the host address
TYPE:
|
port
|
the port number
TYPE:
|
address
|
the address to set for the controller. Defaults to None.
TYPE:
|
relay
|
whether to relay messages. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[Controller, dict[str, Any]]
|
tuple[Controller, dict[str,Any]]: a tuple containing the controller and a dictionary with termination event and thread information. |
create_socket_user
create_socket_user(
host: str,
port: int,
address: str | None = None,
relay: bool = True,
) -> tuple[Controller, dict[str, Any]]
Create a Socket client instance.
PARAMETER | DESCRIPTION |
---|---|
host
|
the host address
TYPE:
|
port
|
the port number
TYPE:
|
address
|
the address to set for the controller. Defaults to None.
TYPE:
|
relay
|
whether to relay messages. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[Controller, dict[str, Any]]
|
tuple[Controller, dict[str,Any]]: a tuple containing the controller and a dictionary with termination event and thread information. |
create_socket_worker
create_socket_worker(
host: str,
port: int,
address: str | None = None,
relay: bool = True,
) -> tuple[Controller, dict[str, Any]]
Create a Socket client instance.
PARAMETER | DESCRIPTION |
---|---|
host
|
the host address
TYPE:
|
port
|
the port number
TYPE:
|
address
|
the address to set for the controller. Defaults to None.
TYPE:
|
relay
|
whether to relay messages. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[Controller, dict[str, Any]]
|
tuple[Controller, dict[str,Any]]: a tuple containing the controller and a dictionary with termination event and thread information. |