Hi-php / phpwebsocket

Automatically exported from code.google.com/p/phpwebsocket
0 stars 0 forks source link

Chrome 19 error after getting response: "A server must not mask any frames that it sends to the client." #55

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Chrome 19 stops connection after receiving message from server with: "A server 
must not mask any frames that it sends to the client."

What steps will reproduce the problem?
First you have to fix chrome so it doesn't disconnect imediatly apon connecting 
by replacing this line:
preg_match ("#Sec-WebSocket-Origin: (.*?)\r\n#", $buffer, $match) && $origin = 
$match[1];
with
preg_match ("#Origin: (.*?)\r\n#", $buffer, $match) && $origin = $match[1];

Then connect to the server with:
php server.php

Then refresh the chrome browser. Firefox 12 works fine.
Send a message to in the chrome 19 browser. It will get to the server and be 
send back. 
This error appears in chrome console.
"A server must not mask any frames that it sends to the client."

I spent a few hours researching the problem and found the solution.
The encode function is the problem.

I couldn't figure out how to not mask the data being sent to the server until I 
found a github example that works and has a flag you can set to not mask the 
data frames.
https://github.com/lemmingzshadow/php-websocket

I replaced the encode function in websocket.class.php with the one in the 
connection.php file in lemmingzshadow's github and it started working. The 
function is called: hybi10Encode in the \server\lib\WebSocket\connection.php 
file.
change this parameter in the function encode: $masked = true to $masked = false 

I am using windows 7 64bit with php 5.4.1

Also there is an updated version of this that might be of use to someone:
http://www.wilky.it/phpwebsocket-new-version/

Original issue reported on code.google.com by stokesc...@gmail.com on 30 Jun 2012 at 6:00

GoogleCodeExporter commented 8 years ago
I am getting alot of errors with this version of phpwebsockets including: 
PHP Warning:  socket_select(): 5 is not a valid Socket resource

and the Sec-WebSocket-Key2 or Sec-WebSocket-Key1 is not used anymore. Use 
Sec-WebSocket-Key.
The above instructions apply to the version of phpwebsocket at: 
http://www.wilky.it/phpwebsocket-new-version/

Someone should put that version into this project since it works with the 
change to the encode function mentioned above about not masking the data being 
sent to the browser. The encode function is needed or the browser doesn't get 
the response from the php server. So I got it all to work but only using his 
code plus my changes.
Also this github has another version entirly for php websockets which is being 
updated regularly:
https://github.com/lemmingzshadow/php-websocket

Original comment by stokesc...@gmail.com on 30 Jun 2012 at 6:27