php - Websockets not working on Google Chrome -
i have server in php binds port , listens sockets. server started in php script with:
$socket = socket_create(af_inet, sock_stream, sol_tcp); socket_set_option($socket, sol_socket, so_reuseaddr, 1); socket_bind($socket, 0, $port);
it listens port:
socket_listen($socket);
when http message arrives client, server reads header:
$header = socket_read($socket_new,1024);
and stores connection in memcache storage. works browsers including safari, firefox , chrome's canary. however, doesn't work on chrome. browser throws error message:
websocket connection 'ws://xyz.com:9001/chat_server.php' failed: error during websocket handshake: wrong 'sec-websocket-accept' header value
my version of chrome is: version 38.0.2125.111 m (64-bit)
we had same issue , solve increasing "maximum number of bytes" parameter in socket_read() function. can seek
socket_tead($socket_new, 2048);
the reason websocket header in chrome greater 1024 bytes. so, when server reads 1024 bytes, not sec-websocket-key parameter , can not generate valid sec-websocket-accept value.
you can utilize fsockopen() , fread() instead of socket_read() function.
php google-chrome websocket
No comments:
Post a Comment