How to send large messages through WebSocket?

I am developing a WebSocket server with C #, and I noticed that all messages coming from the browser (in this case Chrome) using the send () method are 126 characters long. This happens all the time when I want to send messages larger than 126 characters, it seems that the protocol shortens any message larger than 126 characters and transmits only the first 126 characters. I tried to check the protocol definition, but could not find the answer.

So my question is: can I send large messages through WebSockets?

UPDATE: This is how I parse messages from the client (Chrome) on my C # WebSocket server:

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); } } } 

I still do not understand how I can get a larger message, maybe something with the operation code, but I don’t know what to change to make it work?

+7
source share
3 answers

WebSocket messages can be any size. However, large messages are usually transmitted in several parts (fragments) in order to avoid blocking the row header. See WebSockets ID for details.

+6
source

I know that you can send messages larger than 126 characters,
I can send data to protobuf, which contains strings that contain 126 characters. http://www.websocket.org/echo.html
If you look at this site, you can check your posts. (Note that this does not use fragments)

+2
source

It is not true that you said DTB. Sending must necessarily support more than 126 characters. It is a matter of properly formatting your output. If we were limited to 126 characters, there would be no signaling servers for WebRTC. I will encode this send message function and post it here when I finish.

0
source