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

# WebSocket Transport

> WebSocketTransport for the Pipecat C++ SDK: connects native apps to a bot's WebSocket, using Pipecat's ProtobufFrameSerializer.

`pipecat::WebSocketTransport` connects your C++ app to a Pipecat bot over a WebSocket. The bot needs a WebSocket transport, like the [FastAPI WebSocket transport](https://docs.pipecat.ai/api-reference/server/services/transport/fastapi-websocket.md), with Pipecat's `ProtobufFrameSerializer`.

It's part of the [C++ SDK](https://docs.pipecat.ai/api-reference/client/cpp/overview.md), and supports Linux (`x86_64` and `aarch64`), macOS (`aarch64`) and Windows (`x86_64`).

## Usage

Give a `pipecat::WebSocketTransport` to the client when you create it:

```cpp theme={null}
#include <pipecat/pipecat.h>
#include <pipecat/websocket/transport.h>

int main() {
    App app;  // Your pipecat::PipecatClientCallbacks.

    pipecat::PipecatClientOptions options;
    options.transport = std::make_unique<pipecat::WebSocketTransport>();
    options.callbacks = &app;
    pipecat::PipecatClient client(std::move(options));

    // Start a bot with Pipecat's development runner, and connect to it.
    pipecat::APIRequest request;
    request.endpoint = "http://localhost:7860/start";
    request.request_data = {{"transport", "websocket"}};
    client.start_bot_and_connect(request);

    ...

    client.disconnect();
}
```

Then use the client as usual, see the [C++ SDK overview](https://docs.pipecat.ai/api-reference/client/cpp/overview.md#usage).

* The transport connects to the bot's WebSocket. Start endpoints like Pipecat's [development runner](https://docs.pipecat.ai/api-reference/server/utilities/runner/guide.md) (`python bot.py -t websocket`) return its URL, and a token if it needs one, when you ask for the `websocket` transport. If you already have them, connect directly with `client.connect({{"wsUrl", ws_url}, {"token", token}})`.
* The bot serializes its frames with `ProtobufFrameSerializer`, like the [websocket](https://github.com/pipecat-ai/pipecat-examples/tree/main/websocket) example's bot.
* Audio is 16-bit PCM, 16 kHz mono by default. Change it with `pipecat::WebSocketTransportOptions`. The bot's audio is converted to it from whatever the bot sends. The user's audio is sent without echo cancellation, so if you play the bot through speakers, use your platform's echo cancellation or headphones.
* Each client needs its own `WebSocketTransport`, and several clients can run at the same time, e.g. to talk to several bots.

## Installation

Besides what [the client needs](https://docs.pipecat.ai/api-reference/client/cpp/overview.md#installation), the transport uses:

* [libdatachannel](https://github.com/paullouisageneau/libdatachannel) 0.24 or newer, for its WebSocket client. CMake downloads and builds it if it's not installed, which needs OpenSSL.
* [speexdsp](https://github.com/xiph/speexdsp), to convert the bot's audio. If it's not installed, CMake downloads it and builds what the transport needs into it.

With `FetchContent`, turn the transport on before making the SDK available, and link `pipecat::websocket`, which also links the client, see the [C++ SDK overview](https://docs.pipecat.ai/api-reference/client/cpp/overview.md#adding-it-to-your-cmake-project).

To build and install it yourself, add `-DPIPECAT_BUILD_WEBSOCKET=ON` when configuring the SDK:

> [tab] Linux
>
> ```bash theme={null}
> sudo apt-get install libssl-dev
> cmake . -G Ninja -Bbuild -DCMAKE_BUILD_TYPE=Release -DPIPECAT_BUILD_WEBSOCKET=ON
> ninja -C build
> cmake --install build --prefix /path/to/pipecat
> ```

> [tab] macOS
>
> Homebrew doesn't have libdatachannel, so CMake downloads it. It needs Homebrew's OpenSSL, which isn't where CMake looks, so point `OPENSSL_ROOT_DIR` to it:
>
> ```bash theme={null}
> brew install openssl@3
> export OPENSSL_ROOT_DIR=$(brew --prefix openssl@3)
> cmake . -G Ninja -Bbuild -DCMAKE_BUILD_TYPE=Release -DPIPECAT_BUILD_WEBSOCKET=ON
> ninja -C build
> cmake --install build --prefix /path/to/pipecat
> ```

> [tab] Windows
>
> vcpkg installs libdatachannel and speexdsp with the `websocket` feature:
>
> ```bash theme={null}
> cmake --preset vcpkg -DPIPECAT_BUILD_WEBSOCKET=ON -DVCPKG_MANIFEST_FEATURES=websocket
> cmake --build build --config Release
> cmake --install build --config Release --prefix C:/path/to/pipecat
> ```

Then use it as a component of the package:

```cmake theme={null}
find_package(pipecat 1.0 REQUIRED COMPONENTS websocket)
target_link_libraries(my_app PRIVATE pipecat::websocket)
```

If CMake downloaded libdatachannel, it's installed with the transport, as a static library, and your app also needs OpenSSL (on macOS, with `OPENSSL_ROOT_DIR` pointing to it).

## Examples

The SDK's [text](https://github.com/pipecat-ai/pipecat-client-cxx/tree/main/examples/text) and [voice](https://github.com/pipecat-ai/pipecat-client-cxx/tree/main/examples/voice) examples use the WebSocket transport with `--transport websocket`.

## Documentation

> [card] [API Reference](https://docs.pipecat.ai/api-reference/client/cpp/api-reference.md)
>
> Includes `WebSocketTransport` and its options

> [card] [Source](https://github.com/pipecat-ai/pipecat-client-cxx/tree/main/transports/websocket)
>
> The WebSocket transport on GitHub


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.