Server#
- class socketsc.SocketServer#
The socket server class.
- Parameters
address – A tuple with the address and port to bind to
address_family – The address family to use (
socketsc.AF_INETorsocketsc.AF_INET6)sock_type – The socket type to use (Only
socketsc.SOCK_TCPis supported at the moment)
- Returns
A
SocketServerinstance
- serve()#
Start the server
- on(event, callback)#
Register a callback for a specific event
- Parameters
event (str) – The event to register the callback for
callback (Callable[ServerSocketWrapper, Any]) – The callback to register
- emit(event, data=None)#
Emit an event to all connected clients. (Broadcast)
- Parameters
event (str) – The event to emit
data (Any) – The data to send
- remove_listener(event, callback)#
Remove a listener for a specific event
- Parameters
event (str) – The event to remove the listener for
callback (Callable[ServerSocketWrapper, Any]) – The callback to remove
- remove_all_listeners(event)#
Remove all listeners for a specific event
- Parameters
event (str) – The event to remove all listeners for
- class socketsc.ServerSocketWrapper#
This class is used to wrap the client connection socket and provide a way register and emit events for that specific client.
- Parameters
client (Client) – The client instance to wrap
- client_address: Tuple[str, int]#
The address of the client
- client_id: str#
The client uuid
- connection: socket.socket#
The client connection socket
- on(event, callback)#
Register a callback for a specific event
- Parameters
event (str) – The event to register the callback for
callback (Callable[ServerSocketWrapper, Any]) – The callback to register
- emit(event, data)#
Emit an event to the client
- Parameters
event (str) – The event to emit
data (Any) – The data to send
- remove_listener(event, callback)#
Remove a listener for a specific event
- Parameters
event (str) – The event to remove the listener for
callback (Callable[ServerSocketWrapper, Any]) – The callback to remove
- remove_all_listeners(event)#
Remove all listeners for a specific event
- Parameters
event (str) – The event to remove all listeners for