# WebSocket帧超出最大大小：65535字节

- **ID:** `communication/websocket-message-too-large-fragmentation`
- **领域:** communication
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

WebSocket帧的有效载荷超过16位长度限制（65535字节），原因是应用程序在未启用分片或使用扩展帧的情况下发送数据，违反了RFC 6455第5.2节。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Node.js ws 8.13.0 | active | — | — |
| Python websockets 12.0 | active | — | — |
| Go gorilla/websocket 1.5.1 | active | — | — |
| Java Tyrus 2.0.0 | active | — | — |
| Nginx 1.25.0 | active | — | — |

## 解决方案

1. ```
   Enable WebSocket fragmentation in the sender: for Python websockets, use 'await websocket.send(message, fragment_size=16384)' to automatically split large messages into multiple frames.
   ```
2. ```
   Implement application-level chunking: split the payload into chunks of < 65535 bytes on the client and reassemble on the server using a sequence ID.
   ```
3. ```
   Use WebSocket extensions like 'permessage-deflate' to compress data, reducing payload size below the limit.
   ```

## 无效尝试

- **Increase the frame size limit in the WebSocket library configuration** — The RFC mandates a maximum frame payload of 2^16-1 bytes for unfragmented frames; increasing the limit may cause protocol-level errors or disconnection. (85% 失败率)
- **Switch to HTTP/2 streaming instead of WebSocket** — HTTP/2 streaming has different semantics and may not support bidirectional real-time communication; it requires significant application redesign. (90% 失败率)
- **Compress the data before sending to reduce payload size** — Compression may not be feasible for binary data or real-time streams, and it adds CPU overhead; it also doesn't address the root cause of not using fragmentation. (70% 失败率)
