18

Im building a websocket server in chrome packaged apps. I got everything working (handshake and recieving from client to server) but, when I try to send message from Server to Client it always get an error: "failed: A server must not mask any frames that it sends to the client."

This is my prepareMessage code:

  var sendText = _toUTF8Array(JSON.stringify(msg) + '\n');
  var aa;
  var buffer;
  if (sendText.length > 125) {
      if (sendText.length < 65536) {
          aa = new ArrayBuffer(4 + sendText.length);
          buffer = new Uint8Array(aa);
          buffer[0] = 129;
          buffer[1] = 126;
          buffer[2] = sendText.length >> 8;
          buffer[3] = sendText.length & 255;
          _arrayCopy(sendText, 0, buffer, 4, sendText.length);
      }
      else {
          aa = new ArrayBuffer(10 + sendText.length);
          buffer = new Uint8Array(aa);
          buffer[0] = 129;
          buffer[1] = 127;
          var len = new Uint8Array(8);
          len = _Uint64ToUint8(sendText.length);
          var tt = new Uint8Array(8);
          for (var i = 0; i < 8; i++)
          {
              tt[7 - i] = len[i];
          }
          _arrayCopy(tt, 0, buffer, 2, 8);
          _arrayCopy(sendText, 0, buffer, 10, sendText.length);
      }
  }
  else {
      aa = new ArrayBuffer(2 + sendText.length);
      buffer = new Uint8Array(aa);
      buffer[0] = 129;
      buffer[1] = sendText.length;
      _arrayCopy(sendText, 0, buffer, 2, sendText.length);
  }
  return aa;
Caio Keto
  • 1,919
  • 4
  • 20
  • 30
  • Already tested with a C# client (just to see the bytes) and it goes allright. The first bit of second byte (mask) is '0' so, it shouldn't say it is masked. – Caio Keto Jul 02 '13 at 18:02
  • 1
    In order to find the problem, you need to test it in three cases. With a message of length less than 125, between 125 and 65536 and more than that. That way you can find which part of your code is not working. Other than that I can see no problem within your code. It seems compatible with Draft10 and Draft17. Just make sure that your logical operators are doing what they are supposed to do. – Mehran Jul 09 '13 at 15:35
  • check out this discussion of that problem and see if it helps. http://code.google.com/p/phpwebsocket/issues/detail?id=55 – John Faulkner Jul 10 '13 at 16:25
  • 4
    I had this issue for some time. Look at data framing. This is the website I used to figure out this problem. Very simply you are using a coding that is unexpected by the server. http://tools.ietf.org/html/rfc6455#page-27 – Logan Murphy Aug 03 '13 at 13:42

2 Answers2

1

you should use wireshark to see what is wrong with your packets! take a look on https://github.com/mik3fly-4steri5k/groschat, i m currently working on websockets, and it perfectly working on google chrome.

mik3fly-4steri5k
  • 712
  • 3
  • 15
  • 32
-4

Make sure you've enabled the WebSocket protocol in your IIS testing environment.

Control Panel --> Windows Features --> IIS --> WS Module

BTC
  • 3,802
  • 5
  • 26
  • 39
  • This is about implementing a WebSocket __server__ in JavaScript, not accessing one from JavaScript. This has nothing to do with IIS or any other web server. – Piper McCorkle Mar 18 '15 at 17:07