How to upgrade protocol of client side php websocket. I am using phpWebSocket

322

<?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"."\r\n". "Upgrade: WebSocket"."\r\n". "Connection: Upgrade"."\r\n". "Origin: $local"."\r\n". "Host: $host"."\r\n". "Content-Length: ".strlen($data)."\r\n"."\r\n"; ////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.

People are also looking for solutions to the problem: mysql - PHP pagination after concatonation

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.