数据报


🌐 Datagrams

除了流,QUIC还支持不可靠的数据报(RFC 9221),用于需要低延迟、尽力而为消息传递的用例。

🌐 In addition to streams, QUIC supports unreliable datagrams (RFC 9221) for use cases that require low-latency, best-effort messaging.

数据报支持在两个层次上启用。在 QUIC 传输层,两端必须在握手期间都通告一个非零的 maxDatagramFrameSize 传输参数。对于 HTTP/3 会话,两端还必须额外将 application.enableDatagrams 设置为 true,这会在 HTTP/3 控制流上交换 SETTINGS_H3_DATAGRAM 设置。

🌐 Datagram support is enabled at two levels. At the QUIC transport level, both peers must advertise a non-zero maxDatagramFrameSize transport parameter during the handshake. For HTTP/3 sessions, both peers must additionally set application.enableDatagrams to true, which exchanges the SETTINGS_H3_DATAGRAM setting on the HTTP/3 control stream.

使用单次调用 session.sendDatagram() 发送数据报。每个数据报必须适合单个 QUIC 数据包——数据报不能被分片。最大负载大小由对等方的 maxDatagramFrameSize 和路径 MTU 决定。如果数据报过大或对等方不支持数据报,sendDatagram() 会返回 0n,而不是抛出错误。

🌐 A datagram is sent with a single call to session.sendDatagram(). Each datagram must fit within a single QUIC packet — datagrams cannot be fragmented. The maximum payload size is determined by the peer's maxDatagramFrameSize and the path MTU. If a datagram is too large or the peer does not support datagrams, sendDatagram() returns 0n rather than throwing an error.

无法保证送达。数据报可能会丢失、重复,或乱序发送。session.ondatagramstatus 回调报告每个发送的数据报是 'acknowledged''lost' 还是 'abandoned'(从不在网络上发送)。

🌐 There is no guarantee of delivery. Datagrams may be lost, duplicated, or delivered out of order. The session.ondatagramstatus callback reports whether each sent datagram was 'acknowledged', 'lost', or 'abandoned' (never sent on the wire).