Skip to content

Getting Started

André Borchert edited this page Aug 11, 2026 · 26 revisions

Getting Started

Requirements

  • macOS 26 or later
  • Xcode 26.6 or later
  • Swift 6.3.3 or later, using Swift language mode 6

The public integration point is the repository-root Package.swift.

Add the package

.package(
    url: "https://github.com/Pummelchen/WebTransport.git",
    exact: "1.2.0"
)

Add the WebTransport product to your application target. Lower-level products are available for protocol research and specialized integrations; most applications should start with the high-level product.

Connect a client

import Foundation
import WebTransport

let client = WebTransportClient(configuration: WebTransportClientConfiguration(
    authority: "example.com",
    path: "/wt",
    origin: "https://example.com",
    availableProtocols: ["demo.v1"]
))

let session = try await client.connect(
    to: WebTransportEndpoint(host: "example.com", port: 443)
)

let stream = try await session.openBidirectionalStream()
try await stream.send(Data("hello".utf8), endOfStream: true)
let response = try await stream.receive()
try await session.close()

Platform certificate trust is used by default.

Accept a session

import WebTransport

let server = WebTransportServer(configuration: WebTransportServerConfiguration(
    authority: "localhost",
    path: "/wt",
    supportedProtocols: ["demo.v1"],
    localOnly: true
))

let listener = try await server.listen(
    on: WebTransportEndpoint(host: "127.0.0.1", port: 4433)
)
defer { listener.shutdown() }

let session = try await listener.acceptSession()
let stream = try await session.acceptBidirectionalStream()
let request = try await stream.receive()
try await stream.send(request, endOfStream: true)

Server admission can enforce authority, path, origin, supported subprotocols, and HTTP/3 settings. The package does not provide application user authentication.

Run the command-line peers

Start a local IPv4 server:

swift run WebTransportServer --listen 127.0.0.1:4433 --transport packet

Connect from another terminal:

swift run WebTransportClient \
  --connect 127.0.0.1:4433 \
  --transport packet \
  --trust local-self-signed

Use [::1]:4433 for IPv6 loopback. Inspect all options and conformance scenarios with:

swift run WebTransportClient --help
swift run WebTransportServer --list

Real --listen and --connect sessions require packet transport. local-self-signed is explicit, development-only, and restricted to localhost, 127.0.0.1, and ::1.

Session operations

An established WebTransportSession provides:

  • bidirectional stream open and accept operations;
  • datagram send and receive operations when negotiated;
  • graceful drain and close;
  • selected subprotocol and endpoint metadata;
  • session-bound TLS exporter material.

Continue with Architecture, Development and Testing, and Security and Trust.

Clone this wiki locally