I’m programming a web socket server in PHP, because I could not find one that supported the RFC 6455 spec. In doing so, I used the phpwebsocket code as a base and made it RFC 6455 compatible. At least I did for the receive message part. When ever I try to send a message back to the server I get different messages. I’m sure this is due to my skills at bit masking being … terrible. So after quite a bit of trial and error I still have this problem, and I have no idea why.
Time OpCode Mask Length Data
1>2012-06-25T18:05:58.014Z 1 true 4 Ping
2>2012-06-25T18:06:02.121Z 1 true 5 hello
3 2012-06-25T18:06:02.121Z A server must not mask any frames that it sends to the server.
or
3 2012-06-25T18:06:02.121Z Unexpected continuation frame.
I’m using PHP 5.4.4 on my computer, using the command line interface. php ws.php is all I need to do in order to start the web socket server. I then use the wsClient.html as my client. Using the latest version of Google Chrome (21.0.1180.4 dev-m) on Windows 8 Preview I’m getting the following message.
You can download the php server and client from my github repo and play long from there. The problem is in the WebSockets::send function.
private function send($client, $payload)
{
$frame = pack('C2a*', 0b10000001, 0b01111111 & strlen($payload), $payload);
socket_write($client, $frame, strlen($frame));
}
What am I doing wrong?
My problem was that I was using little-endian style and not big-endian style when using the binary syntax. I was doing
0b10000001, 0b01111111when I should be been doing0b10000001, 0b11111110.