ghedipunk / PHP-Websockets

A Websockets server written in PHP.
BSD 3-Clause "New" or "Revised" License
913 stars 375 forks source link

TCP Connection Lost #115

Closed renznamoc21 closed 5 years ago

renznamoc21 commented 5 years ago

TCP Connection lost when connect to websocket server from my php codeigniter function

$port = 9000; $local = "http://localhost/"; //url where this script run $data = 'hello world!'; //data to be send $acceptKey = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'; $acceptKey = sha1($acceptKey, true); $head = "GET / HTTP/1.1"."\r\n". "Upgrade: WebSocket"."\r\n". "Sec-WebSocket-Version: 13"."\r\n". "Sec-WebSocket-Key: $acceptKey"."\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, 2000000); // var_dump($headers); fwrite($sock, "\x00$data\xff" ) or die('error:'.$errno.':'.$errstr); $wsdata = fread($sock, 2000000); //receives the data included in the websocket package "\x00DATA\xff" var_dump($wsdata); fclose($sock);

am i doing it right ?

thank you