【发布时间】:2015-07-28 17:30:51
【问题描述】:
在客户端 API 中公开 WebSocket 碎片是否有任何价值?
阅读 RFC 6455,我确信非连续帧并不能保证您在语义方面的任何事情。不应依赖帧边界。这太冒险了。规范明确解决了这个问题:
Unless specified otherwise by an extension, frames have no semantic
meaning. An intermediary might coalesce and/or split frames, if no
extensions were negotiated by the client and the server or if some
extensions were negotiated, but the intermediary understood all the
extensions negotiated and knows how to coalesce and/or split frames
in the presence of these extensions. One implication of this is that
in absence of extensions, senders and receivers must not depend on
the presence of specific frame boundaries.
因此,接收到二进制或文本类型的非连续帧并不意味着它是从通道另一端发送的原子且有意义的东西。同样,连续帧序列并不意味着合并它们会产生有意义的消息。而更令人不安的是, 单个非连续类型的帧可能是合并许多其他帧的结果。
总而言之,通过 WebSocket 发送的字节组几乎可以以任何方式重新组合,因为字节顺序是相同的(这当然是在没有扩展的情况下)。
如果是这样,那么引入这个概念是否有用?也许最好将其隐藏为实现细节?我想知道 WebSocket 用户是否发现它在 Netty、Jetty、Grizzly 等产品中很有用。谢谢。
【问题讨论】:
标签: websocket jetty netty grizzly