> ## Documentation Index
> Fetch the complete documentation index at: https://daily-main.mintlify.site/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](/api-reference/server/services/transport/fastapi-websocket), with Pipecat's `ProtobufFrameSerializer`.

It's part of the [C++ SDK](/api-reference/client/cpp/overview), 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](/api-reference/client/cpp/overview#usage).

* The transport connects to the bot's WebSocket. Start endpoints like Pipecat's [development runner](/api-reference/server/utilities/runner/guide) (`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](/api-reference/client/cpp/overview#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](/api-reference/client/cpp/overview#adding-it-to-your-cmake-project).

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

<Tabs>
  <Tab title="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>

  <Tab title="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>

  <Tab title="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
    ```
  </Tab>
</Tabs>

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

<CardGroup cols={2}>
  <Card title="API Reference" icon="book" href="/api-reference/client/cpp/api-reference">
    Includes `WebSocketTransport` and its options
  </Card>

  <Card title="Source" icon="github" href="https://github.com/pipecat-ai/pipecat-client-cxx/tree/main/transports/websocket">
    The WebSocket transport on GitHub
  </Card>
</CardGroup>


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