WebSocket library bug?

28 Nov 2012

I tried the websocket library to send some Json messages to the pywebsocket server. But the server couldn't receive any messages. I inspected the websocket library and found that byte order of the length field is not correct. I think that the following corrections are required.

sendChar(len & 0xff);

sendChar((len >> 8) & 0xff);

sendChar((len >> 8) & 0xff);

sendChar(len & 0xff);

28 Nov 2012

Hi,

Are you using the WebSocketClient library ? You can find an HelloWorld example here.

Cheers, Sam

28 Nov 2012

Hi,

When packet length is shorter than 126 bytes, the library operates normally. However, I think that there is a problem when packet length is 126 bytes or more.

Regards, Kaz

28 Nov 2012

Hi Kaz,

I think that you are using a really old version of the websocket library. There is not this problem in the new WebsocketClient library.

The code in the websocketclient library looks like:

    if (len < 65535) {
        msg[0] = 126 | (1<<7);
        msg[1] = (len >> 8) & 0xff;
        msg[2] = len & 0xff;
        return 3;
    }

Cheers, Sam

29 Nov 2012

Hi, Sam

I'll try to rewrite my code by WebsocketClient library. Thank you for your help.

Regards, Kaz