IOWebsockets

IOWebsockets(websocket: ServerConnection)

A websocket input/output stream.
Initialize the websocket input/output stream.

Parameters:
NameDescription
websocketType: autogen.io.websockets.ServerConnection

Instance Attributes

websocket


The URI of the websocket server.

Instance Methods

get_default

get_default() -> IOStream

Get the default input/output stream.
Returns:
IOStream: The default input/output stream.

Returns:
TypeDescription
IOStreamIOStream: The default input/output stream.

get_global_default

get_global_default() -> IOStream

Get the default input/output stream.
Returns:
IOStream: The default input/output stream.

Returns:
TypeDescription
IOStreamIOStream: The default input/output stream.

input

input(
    self,
    prompt: str = '',
    *,
    password: bool = False
) -> str

Read a line from the input stream.

Parameters:
NameDescription
promptThe prompt to display.

Defaults to "".

Type: str

Default:
passwordWhether to read a password.

Defaults to False.

Type: bool

Default: False
Returns:
TypeDescription
strstr: The line read from the input stream.

print

print(
    self,
    *objects: Any,
    sep: str = ' ',
    end: str = '\n',
    flush: bool = False
) -> None

Print data to the output stream.

Parameters:
NameDescription
*objectsType: Any
sepThe separator between objects.

Defaults to ” ”.

Type: str

Default: ’ ‘
endThe end of the output.

Defaults to “

Type: str

Default: ‘\n’
flushWhether to flush the output.

Defaults to False.

Type: bool

Default: False

run_server_in_thread

run_server_in_thread(
    *,
    host: str = '127.0.0.1',
    port: int = 8765,
    on_connect: Callable[[ForwardRef('IOWebsockets')], None],
    ssl_context: SSLContext | None = None,
    **kwargs: Any
) -> Iterator[str]

Factory function to create a websocket input/output stream.

Parameters:
NameDescription
hostThe host to bind the server to.

Defaults to “127.0.0.1”.

Type: str

Default: ‘127.0.0.1’
portThe port to bind the server to.

Defaults to 8765.

Type: int

Default: 8765
on_connectThe function to be executed on client connection.

Typically creates agents and initiate chat.

Type: Callable[[ForwardRef(‘IOWebsockets’)], None]
ssl_contextThe SSL context to use for secure connections.

Defaults to None.

Type: ssl.SSLContext | None

Default: None
**kwargsType: Any

send

send(self, message: BaseEvent) -> None

Send a message to the output stream.

Parameters:
NameDescription
messageThe message to send.

Type: BaseEvent

set_default

set_default(stream: ForwardRef('IOStream') | None) -> Iterator[None]

Set the default input/output stream.

Parameters:
NameDescription
streamThe input/output stream to set as the default.

Type: ForwardRef(‘IOStream’) | None

set_global_default

set_global_default(stream: IOStream) -> None

Set the default input/output stream.

Parameters:
NameDescription
streamThe input/output stream to set as the default.

Type: IOStream