Skip to main content

Overview

The SCTPTransport provides details about the SCTP (Stream Control Transmission Protocol) transport layer that manages data channel connections. It handles the establishment and management of the SCTP association over a DTLS transport.

Type Definition

The SCTPTransport manages the SCTP association, data channel creation, and state transitions.

Creating an SCTPTransport

NewSCTPTransport

Creates a new SCTPTransport. This constructor is part of the ORTC API and is not meant to be used together with the basic WebRTC API.
*DTLSTransport
required
The DTLS transport instance to send SCTP packets over.
*SCTPTransport
The newly created SCTPTransport instance.

Properties

Transport

Returns the DTLSTransport instance the SCTPTransport is sending over.

State

Returns the current state of the SCTPTransport.
SCTPTransportState
One of: SCTPTransportStateConnecting, SCTPTransportStateConnected, or SCTPTransportStateClosed.

MaxChannels

Returns the maximum number of RTCDataChannels that can be open simultaneously.
uint16
The maximum channel count (default: 65535).

BufferedAmount

Returns the total amount (in bytes) of currently buffered user data across all data channels.
int
The total buffered bytes.

Capabilities

GetCapabilities

Returns the SCTPCapabilities of the SCTPTransport, including the maximum message size.
SCTPCapabilities
Capabilities object containing MaxMessageSize and other SCTP settings.

Lifecycle Management

Start

Starts the SCTPTransport. Since both local and remote parties must mutually create an SCTPTransport, SCTP SO (Simultaneous Open) is used to establish a connection over SCTP.
SCTPCapabilities
required
The SCTP capabilities to use for the connection, including MaxMessageSize. If MaxMessageSize is 0, it defaults to the implementation’s default value.
error
Returns an error if the DTLS transport is not ready, if the SCTP association cannot be established, or if data channels fail to open.
Calling Start() multiple times is safe; subsequent calls will be ignored if already started.

Stop

Stops the SCTPTransport by aborting the SCTP association and closing all data channels.
error
Returns an error if the stop operation fails.

Event Handlers

OnDataChannel

Sets an event handler invoked when a data channel message arrives from a remote peer.
func(*DataChannel)
required
The callback function to invoke when a new data channel is received.
This handler runs synchronously to allow setup to complete before data channel event handlers are called.

OnDataChannelOpened

Sets an event handler invoked when a data channel is fully opened and ready to use.
func(*DataChannel)
required
The callback function to invoke when a data channel opens.

OnError

Sets an event handler invoked when the SCTP Association encounters an error.
func(err error)
required
The callback function to invoke when an error occurs.

OnClose

Sets an event handler invoked when the SCTP Association closes.
func(err error)
required
The callback function to invoke when the transport closes. The error parameter will be nil for clean closes.

Statistics

Stats

Reports the current statistics of the SCTPTransport.
SCTPTransportStats
Statistics object containing detailed transport metrics.

Internal Operations

The SCTPTransport automatically handles several internal operations:
The transport automatically generates unique IDs for data channels based on the DTLS role:
  • Client role: Uses even IDs (0, 2, 4, …)
  • Server role: Uses odd IDs (1, 3, 5, …)
This ensures no ID conflicts between peers.
When a remote peer creates a data channel, the transport:
  1. Accepts the incoming SCTP stream
  2. Parses the channel configuration
  3. Creates a local DataChannel object
  4. Triggers the OnDataChannel handler
  5. Triggers the OnDataChannelOpened handler when ready
The transport handles different reliability modes:
  • Reliable ordered: Standard TCP-like behavior
  • Reliable unordered: All messages delivered, order not guaranteed
  • Partial reliable with retransmit limit: Limited retransmission attempts
  • Partial reliable with time limit: Messages expire after time window
Each mode uses different SCTP channel types internally.

Complete Example

Configuration Options

The SCTP transport behavior can be customized through the SettingEngine before creating the API:
Changing SCTP settings can significantly impact performance and reliability. Only modify these if you understand the implications.

Best Practices

Handle Errors

Always set up OnError handlers to catch and handle SCTP association errors gracefully.

Monitor State

Check the transport state before performing operations to avoid errors on closed connections.

Configure Limits

Set appropriate MaxMessageSize based on your application’s needs and network conditions.

Clean Shutdown

Call Stop() when done to properly clean up resources and close all data channels.

DataChannel

Individual data channels running over this SCTP transport

DTLSTransport

The underlying DTLS transport for secure communication

SCTPCapabilities

Capabilities and configuration for SCTP connections

SCTPTransportState

State enumeration for transport lifecycle