# RTCDataChannel

> The `RTCDataChannel` JS object is a channel for sending arbitrary data between WebRTC peers.

## What is an RTCDataChannel?

The object that sends text or binary messages directly between peers over an `RTCPeerConnection`. Can be reliable and ordered or fast and unordered, which suits games, file transfer and sending events alongside a call.

- Topic: Media & Audio
- Type: object
- Browser support: Chrome 24+, Chrome Android 25+, Edge 79+, Firefox 22+, Firefox Android 24+, Safari 11+, Safari iOS 11+

## Example

Wrong:

```js
const channel = pc.createDataChannel('chat');
channel.send('hello');
```

Right:

```js
const channel = pc.createDataChannel('chat');
channel.addEventListener('open', () => {
  channel.send('hello');
});
```

`send()` throws while the channel is still connecting, so wait for the `open` event.

## Common mistakes

- Calling `send()` before the channel opens and getting an 'InvalidStateError'.

## Key points

- Messages are sent only after the channel's `open` event.
- Large files are split into chunks instead of being sent as one message.

## Interview questions

### Is RTCDataChannel reliable like TCP?

By default, yes: delivery is reliable and ordered. Pass `ordered: false` or `maxRetransmits` to `createDataChannel()` for faster, lossy delivery.

### How does the remote peer receive a data channel?

It gets the channel in the `datachannel` event of its `RTCPeerConnection` and listens for `message` events on it.

### RTCDataChannel vs WebSocket?

A data channel sends data peer to peer once signaling is done. A WebSocket always goes through a server.

## Related cards

- [RTCPeerConnection](https://wonderium.dev/js/rtc-peer-connection.md)
- [WebRTC](https://wonderium.dev/web/webrtc.md)
- [Peer-to-Peer](https://wonderium.dev/web/peer-to-peer.md)

---

- Level: [JavaScript](https://wonderium.dev/js.md)
- HTML version: https://wonderium.dev/js/rtc-data-channel
- Last updated: 2026-11-25
