0

I'm trying to send some data from server written in C# to browser client written in JS. When I send 12900 bytes sized messages then all going OK. If I'll send message sized 67990 bytes then on server-side I'll get no error and client side I'll get disconnect with disconnect error 1006 with no other explanation. I can't find somewhere any limitations related to message size. Here is C# code in which I'm trying to send data.

byte[] data =getDecodedMessage(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(dataResponse)));
stream.Write(data, 0, data.Length);
  • hmm could you try any mitm proxy to debug your error ? (u could use fiddler) – Agent_Orange Mar 14 '18 at 15:34
  • Plenty of hits if you search for : socket error 1006. He is one good example : https://support.pusher.com/hc/en-us/articles/204202193-What-is-meant-by-Error-1006- – jdweng Mar 14 '18 at 16:13

1 Answers1

0

Based on question user3892585 answer I replaced bytesRaw.Length with bytesRaw.LongLengthin my encoding function for WebSocket data transfer. After doing this I didn't receive socket error.

public static byte[] getEncodedMessage(byte[] bytesRaw)
    {
        List<byte> bytesFormatted = new List<byte>();
        bytesFormatted.Add(129);

        int indexStartRawData = -1; // it doesn't matter what value is
                                    // set here - it will be set now:

        if (bytesRaw.LongLength <= 125)
        {
            bytesFormatted.Add(Convert.ToByte(bytesRaw.LongLength));


            indexStartRawData = 2;
        }

        else if (bytesRaw.LongLength >= 126 && bytesRaw.LongLength <= 65535)
        {
            bytesFormatted.Add(126);
            bytesFormatted.Add(Convert.ToByte((bytesRaw.LongLength >> 8) & 255));
            bytesFormatted.Add(Convert.ToByte((bytesRaw.LongLength) & 255));

            indexStartRawData = 4;
        }

        else
        {
            bytesFormatted.Add(127);
            bytesFormatted.Add(Convert.ToByte((bytesRaw.LongLength >> 56) & 255));
            bytesFormatted.Add(Convert.ToByte((bytesRaw.LongLength >> 48) & 255));


            bytesFormatted.Add(Convert.ToByte((bytesRaw.LongLength >> 40) & 255));
            bytesFormatted.Add(Convert.ToByte((bytesRaw.LongLength >> 32) & 255));
            bytesFormatted.Add(Convert.ToByte((bytesRaw.LongLength >> 24) & 255));
            bytesFormatted.Add(Convert.ToByte((bytesRaw.LongLength >> 16) & 255));
            bytesFormatted.Add(Convert.ToByte((bytesRaw.LongLength >> 8) & 255));
            bytesFormatted.Add(Convert.ToByte((bytesRaw.LongLength) & 255));

            indexStartRawData = 10;
        }
        // put raw data at the correct index
        bytesFormatted.InsertRange(indexStartRawData, bytesRaw);
        return bytesFormatted.ToArray();
    }