Server#
- class sayd.SaydServer(host: Optional[Union[str, list]] = None, port: int = 7050, queue: int = 512, limit: int = 1024, buffer: int = 128, timeout: int = 3, ping: int = 1, logger: Optional[Logger] = None, cert: Optional[str] = None, cert_key: Optional[str] = None)#
Server class.
- Parameters
host (Optional[Union[str, list]]) – A list of addresses or a address to bind the server, defaults to None.
port (int) – Port to use, defaults to 7050.
queue (int) – Limit of clients waiting to connect, defaults to 512.
limit (int) – Limit of connected clients, defaults to 1024.
buffer (int) – Buffer size limit per client in KiB, defaults to 128.
timeout (int) – Time in seconds to disconnect a client that is not responding, defaults to 3.
ping (int) – Frequency in seconds to ping the clients, defaults to 1.
logger (Optional[Logger]) – Logger to use, defaults to None.
cert (Optional[str]) – Path to the TLS certificate, defaults to None.
cert_key (Optional[str]) – Path to the TLS certificate key, defaults to None.
- add_callback(name: str, function: Callable) None#
Method to bind functions to be called when a request is received.
- Parameters
name (str) – Name to bind the function.
function (Callable) – Function to bind.
- blacklist(host: str) None#
Method to add a host to the blacklist.
- Parameters
host (str) – Host to block.
- async call(name: str, data: Optional[dict] = None, instance: Optional[str] = None, address: Optional[tuple] = None, wait: bool = True, wait_timeout: int = 3, _call_id: Optional[str] = None) Optional[Union[dict, list, bool, Exception]]#
Calls a function in a remote client or in all clients (broadcast) if address is not specified.
- Parameters
name (str) – Name of the function.
data (dict) – Data to send, defaults to None.
instance (Optional[str]) – Instance to pass to the remote function, defaults to None.
address (Optional[tuple]) – Client address, defaults to None.
wait (bool) – True to wait for a answer, defaults to True.
wait_timeout (int) – Time limit in seconds to wait for a answer, defaults to 3.
- Returns
The call result.
- Return type
Union[dict, list, bool, Exception, None]
- callback(name: str) Callable#
Decorator to bind functions to be called when a request is received.
- Parameters
name (str) – Name to bind the function.
- property clients: Set[tuple]#
Returns the connected clients.
- Returns
A set containing the clients.
- Return type
Set[tuple]
- async start() None#
Starts the server.
- async stop() None#
Stops the server.
- unblacklist(host: str) None#
Method to remove a host from the blacklist.
- Parameters
host (str) – Host to unblock.