io
io.websockets
ServerConnection
send
Send a message to the client.
Arguments:
message
Union[Data, Iterable[Data]] - The message to send.
recv
Receive a message from the client.
Arguments:
timeout
Optional[float], optional - The timeout for the receive operation. Defaults to None.
Returns:
Data
- The message received from the client.
close
Close the connection.
WebSocketServer
serve_forever
Run the server forever.
shutdown
Shutdown the server.
__enter__
Enter the server context.
__exit__
Exit the server context.
IOWebsockets
A websocket input/output stream.
__init__
Initialize the websocket input/output stream.
Arguments:
websocket
ServerConnection - The websocket server.
Raises:
ImportError
- If the websockets module is not available.
run_server_in_thread
Factory function to create a websocket input/output stream.
Arguments:
host
str, optional - The host to bind the server to. Defaults to “127.0.0.1”.port
int, optional - The port to bind the server to. Defaults to 8765.on_connect
Callable[[IOWebsockets], None] - The function to be executed on client connection. Typically creates agents and initiate chat.ssl_context
Optional[ssl.SSLContext], optional - The SSL context to use for secure connections. Defaults to None.kwargs
Any - Additional keyword arguments to pass to the websocket server.
Yields:
str
- The URI of the websocket server.
websocket
The URI of the websocket server.
Print data to the output stream.
Arguments:
objects
any - The data to print.sep
str, optional - The separator between objects. Defaults to ” ”.end
str, optional - The end of the output. Defaults to ” ”.flush
bool, optional - Whether to flush the output. Defaults to False.
input
Read a line from the input stream.
Arguments:
prompt
str, optional - The prompt to display. Defaults to "".password
bool, optional - Whether to read a password. Defaults to False.
Returns:
str
- The line read from the input stream.