duancan1900 2015-05-17 19:57
浏览 96

如何升级客户端php websocket的协议。 我正在使用phpWebSocket

<?php $host = 'localhost'; //where is the websocket server $port = 8080; //ssl $local = "http://localhost/php-websockets-master/"; //url where this script run $data = '{"id": 2,"command": "server_info"}'; //data to be send $head = "GET / HTTP/1.1"." ". "Upgrade: WebSocket"." ". "Connection: Upgrade"." ". "Origin: $local"." ". "Host: $host"." ". "Content-Length: ".strlen($data)." "." "; ////WebSocket handshake $sock = fsockopen($host, $port, $errno, $errstr, 2); fwrite($sock, $head ) or die('error:'.$errno.':'.$errstr); $headers = fread($sock, 2000); sleep(1); fwrite($sock, "\x00$data\xff" ) or die('error:'.$errno.':'.$errstr); $wsdata = fread($sock, 2000); //receives the data included in the websocket package "\x00DATA\xff" $retdata = trim($wsdata,"\x00\xff"); //extracts data ////WebSocket handshake fclose($sock); echo $headers; echo $retdata; ?>

is the code I am using and the server side just echoes the string sent to it. I have tested server side code written in php and it works fine with javascript client side code. When the above mentioned code is ran, it prints only header and that is "HTTP/1.1 426 Upgrade Required Sec-WebSocketVersion: 13". Any help explaining it would be great. Please don't suggest using Ratchet or React php. If You can suggest some library that does not need to be installed then that too would be of great help.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!