Documentation Index
Fetch the complete documentation index at: https://mintlify.com/pion/webrtc/llms.txt
Use this file to discover all available pages before exploring further.
Overview
TheSCTPTransport 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
Creating an SCTPTransport
NewSCTPTransport
The DTLS transport instance to send SCTP packets over.
The newly created SCTPTransport instance.
Properties
Transport
State
One of:
SCTPTransportStateConnecting, SCTPTransportStateConnected, or SCTPTransportStateClosed.MaxChannels
The maximum channel count (default: 65535).
BufferedAmount
The total buffered bytes.
Capabilities
GetCapabilities
Capabilities object containing MaxMessageSize and other SCTP settings.
Lifecycle Management
Start
The SCTP capabilities to use for the connection, including MaxMessageSize. If MaxMessageSize is 0, it defaults to the implementation’s default value.
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
Returns an error if the stop operation fails.
Event Handlers
OnDataChannel
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
The callback function to invoke when a data channel opens.
OnError
The callback function to invoke when an error occurs.
OnClose
The callback function to invoke when the transport closes. The error parameter will be nil for clean closes.
Statistics
Stats
Statistics object containing detailed transport metrics.
Internal Operations
The SCTPTransport automatically handles several internal operations:Data Channel ID Generation
Data Channel ID Generation
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, …)
Data Channel Acceptance
Data Channel Acceptance
When a remote peer creates a data channel, the transport:
- Accepts the incoming SCTP stream
- Parses the channel configuration
- Creates a local DataChannel object
- Triggers the
OnDataChannelhandler - Triggers the
OnDataChannelOpenedhandler when ready
Reliability Configuration
Reliability Configuration
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
Complete Example
Configuration Options
The SCTP transport behavior can be customized through theSettingEngine before creating the API:
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.Related Types
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