dongzhiju0324 2014-11-07 23:39
浏览 331
已采纳

Web浏览器无法在Google Chrome上运行

I have a server in PHP which binds to a port and listens to sockets. My server is started in a 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 then listens to the port:

socket_listen($socket);

When a HTTP message arrives from the client, the server reads the header:

$header = socket_read($socket_new,1024);

and then stores the connection in a Memcache storage. This works for most browsers including safari, firefox and Chrome's Canary. However, it doesn't work on chrome. The browser throws an error message:

WebSocket connection to 'ws://xyz.com:9001/chat_server.php' failed: Error during WebSocket handshake: Incorrect 'Sec-WebSocket-Accept' header value

My version of Chrome is: Version 38.0.2125.111 m (64-bit)

  • 写回答

1条回答 默认 最新

  • dsk88199 2014-11-07 23:50
    关注

    We had the same issue and we could solve it by increasing the "maximum number of bytes" parameter in the socket_read() function. You can try

    socket_tead($socket_new, 2048);
    

    The reason is that websocket header in chrome sometimes is greater that 1024 bytes. So, when your server reads 1024 bytes, it does not get Sec-Websocket-Key parameter and it can not generate valid Sec-Websocket-Accept value.

    You can also use fsockopen() and fread() instead of socket_read() function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于#flink#的问题:关于docker部署flink集成hadoop的yarn,请教个问题flink启动yarn-session.sh连不上hadoop
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题