如何通过WebSocket发送更大的消息?

我正在用C#开发一个WebSocket服务器,我注意到使用send()方法来自浏览器(在这种情况下是Chrome)的所有消息都是126个字符长度最大值。 它总是发生在我想要发送大于126个字符的消息时,看起来协议会切断大于126个字符的消息并仅传输前126个字符。 我试图检查协议定义,但没有找到任何答案。

所以,我的问题是,我可以通过WebSockets发送更大的消息吗?

更新:这是我在C#WebSocket服务器中解析来自客户端(Chrome)的消息的方式:

private void ReceiveCallback(IAsyncResult _result) { lock (lckRead) { string message = string.Empty; int startIndex = 2; Int64 dataLength = (byte)(buffer[1] & 0x7F); // when the message is larger then 126 chars it cuts here and all i get is the first 126 chars if (dataLength > 0) { if (dataLength == 126) { BitConverter.ToInt16(buffer, startIndex); startIndex = 4; } else if (dataLength == 127) { BitConverter.ToInt64(buffer, startIndex); startIndex = 10; } bool masked = Convert.ToBoolean((buffer[1] & 0x80) >> 7); int maskKey = 0; if (masked) { maskKey = BitConverter.ToInt32(buffer, startIndex); startIndex = startIndex + 4; } byte[] payload = new byte[dataLength]; Array.Copy(buffer, (int)startIndex, payload, 0, (int)dataLength); if (masked) { payload = MaskBytes(payload, maskKey); message = Encoding.UTF8.GetString(payload); OnDataReceived(new DataReceivedEventArgs(message.Length, message)); } HandleMessage(message); //'message' - the message that received Listen(); } else { if (ClientDisconnected != null) ClientDisconnected(this, EventArgs.Empty); } } } 

我仍然不明白我怎么能得到更大的消息,它可能与操作码有关,但我不知道要改变什么使它工作?

WebSocket消息可以是任何大小。 但是,大型消息通常以多个部分(片段)传输,以避免线头阻塞。 有关详细信息,请参阅WebSockets ID 。

我知道您可以发送超过126个字符的消息,
我能够通过protobuf发送数据,其中包含本身包含126个字符的字符串。 http://www.websocket.org/echo.html
如果你看这个网站,你可以测试你的消息。 (注意这不使用片段)

你说DTB的说法不正确。 发送肯定应该支持超过126个字符。 这是正确格式化输出的问题。 如果我们限制在126个字符,那么WebRTC就没有信令服务器。 我将编写此发送消息function并在此完成后将其发布到此处。