> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ag2.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# autogen.io.IOWebsockets

<h2 id="autogen.io.IOWebsockets" class="doc doc-heading">
  <code class="doc-symbol doc-symbol-heading doc-symbol-class" />

  <span class="doc doc-object-name doc-class-name">IOWebsockets</span>
</h2>

```python theme={null}
IOWebsockets(websocket: ServerConnection)
```

A websocket input/output stream.<br />Initialize the websocket input/output stream.<br />

<b>Parameters:</b>

| Name        | Description                                      |
| ----------- | ------------------------------------------------ |
| `websocket` | **Type:** autogen.io.websockets.ServerConnection |

### Instance Attributes

<code class="doc-symbol doc-symbol-heading doc-symbol-attribute" />

#### websocket

<br />

The URI of the websocket server.

### Instance Methods

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### get\_default

```python theme={null}
get_default() -> IOStreamProtocol | AsyncIOStreamProtocol
```

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

<b>Returns:</b>

| Type                                                                                                                                                 | Description                                |
| ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| [IOStreamProtocol](/docs/api-reference/autogen/io/IOStreamProtocol) \| [AsyncIOStreamProtocol](/docs/api-reference/autogen/io/AsyncIOStreamProtocol) | IOStream: The default input/output stream. |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### get\_global\_default

```python theme={null}
get_global_default() -> IOStreamProtocol | AsyncIOStreamProtocol
```

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

<b>Returns:</b>

| Type                                                                                                                                                 | Description                                |
| ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| [IOStreamProtocol](/docs/api-reference/autogen/io/IOStreamProtocol) \| [AsyncIOStreamProtocol](/docs/api-reference/autogen/io/AsyncIOStreamProtocol) | IOStream: The default input/output stream. |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### input

```python theme={null}
input(
    self,
    prompt: str = '',
    *,
    password: bool = False
) -> str
```

Read a line from the input stream.<br />

<b>Parameters:</b>

| Name       | Description                                                                                                       |
| ---------- | ----------------------------------------------------------------------------------------------------------------- |
| `prompt`   | The prompt to display.<br /><br />Defaults to "".<br /><br />**Type:** str<br /><br />**Default:** ''             |
| `password` | Whether to read a password.<br /><br />Defaults to False.<br /><br />**Type:** bool<br /><br />**Default:** False |

<b>Returns:</b>

| Type | Description                               |
| ---- | ----------------------------------------- |
| str  | str: The line read from the input stream. |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### print

```python theme={null}
print(
    self,
    *objects: Any,
    sep: str = ' ',
    end: str = '\n',
    flush: bool = False
) -> None
```

Print data to the output stream.<br />

<b>Parameters:</b>

| Name       | Description                                                                                                        |
| ---------- | ------------------------------------------------------------------------------------------------------------------ |
| `*objects` | **Type:** Any                                                                                                      |
| `sep`      | The separator between objects.<br /><br />Defaults to " ".<br /><br />**Type:** str<br /><br />**Default:** ' '    |
| `end`      | The end of the output.<br /><br />Defaults to "<br /><br />**Type:** str<br /><br />**Default:** '\n'              |
| `flush`    | Whether to flush the output.<br /><br />Defaults to False.<br /><br />**Type:** bool<br /><br />**Default:** False |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### run\_server\_in\_thread

```python theme={null}
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.<br />

<b>Parameters:</b>

| Name          | Description                                                                                                                                                                                                                 |
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `host`        | The host to bind the server to.<br /><br />Defaults to "127.0.0.1".<br /><br />**Type:** str<br /><br />**Default:** '127.0.0.1'                                                                                            |
| `port`        | The port to bind the server to.<br /><br />Defaults to 8765.<br /><br />**Type:** int<br /><br />**Default:** 8765                                                                                                          |
| `on_connect`  | The function to be executed on client connection.<br /><br />Typically creates agents and initiate chat.<br /><br />**Type:** Callable\[\[ForwardRef('[IOWebsockets](/docs/api-reference/autogen/io/IOWebsockets)')], None] |
| `ssl_context` | The SSL context to use for secure connections.<br /><br />Defaults to None.<br /><br />**Type:** ssl.SSLContext \| None<br /><br />**Default:** None                                                                        |
| `**kwargs`    | **Type:** Any                                                                                                                                                                                                               |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### send

```python theme={null}
send(self, message: BaseEvent) -> None
```

Send a message to the output stream.<br />

<b>Parameters:</b>

| Name      | Description                                                                                         |
| --------- | --------------------------------------------------------------------------------------------------- |
| `message` | The message to send.<br /><br />**Type:** [BaseEvent](/docs/api-reference/autogen/events/BaseEvent) |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### set\_default

```python theme={null}
set_default(stream: IOStreamProtocol | AsyncIOStreamProtocol | None) -> Iterator[None]
```

Set the default input/output stream.<br />

<b>Parameters:</b>

| Name     | Description                                                                                                                                                                                                                      |
| -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `stream` | The input/output stream to set as the default.<br /><br />**Type:** [IOStreamProtocol](/docs/api-reference/autogen/io/IOStreamProtocol) \| [AsyncIOStreamProtocol](/docs/api-reference/autogen/io/AsyncIOStreamProtocol) \| None |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### set\_global\_default

```python theme={null}
set_global_default(stream: IOStreamProtocol | AsyncIOStreamProtocol) -> None
```

Set the default input/output stream.<br />

<b>Parameters:</b>

| Name     | Description                                                                                                                                                                                                              |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `stream` | The input/output stream to set as the default.<br /><br />**Type:** [IOStreamProtocol](/docs/api-reference/autogen/io/IOStreamProtocol) \| [AsyncIOStreamProtocol](/docs/api-reference/autogen/io/AsyncIOStreamProtocol) |

<br />
