0PricingLogin
Real-Time Streaming Systems (WebRTC + Live Data) · Lesson

Sending and Receiving Data

Implement code examples for sending and receiving various types of data (text, binary) over an established WebRTC Data Channel.

Messaging with Data Channels

WebRTC's RTCDataChannel isn't just for connection; it's also for sending messages! This lets peers exchange arbitrary data directly.

Think of it like a super-fast, secure chat line between two browsers, but for any kind of information you want to share.

Sending Data with `send()`

To send data, you use the send() method of an RTCDataChannel object. It's straightforward and can handle various data types.

  • Syntax: dataChannel.send(data);
  • The data can be a String, Blob, ArrayBuffer, or ArrayBufferView.

The channel must be in an 'open' state to send messages.

All lessons in this course

  1. Introduction to RTCDataChannel
  2. Sending and Receiving Data
  3. Practical Data Channel Use Cases
  4. Reliable vs Unreliable Data Channels
← Back to Real-Time Streaming Systems (WebRTC + Live Data)