I am developing a WebSocket server with C# and I noticed that all the messages that coming from the browser (Chrome in that case) using the send() method are 126 chars length max. It happens all the time when I want to send messages larger that 126 chars, looks like the protocol cuts any message larger then 126 chars and transfer only the first 126 chars. I tried to check on the protocol definition but didn't find any answer.
So, my question is, can I send larger messages over WebSockets?
UPDATE: This is the way that I'm parsing the messages from the client (Chrome) in 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 didn't understand how can I get larger message, its maybe something with the opcode, but I don't know what to change to make it work?