无法使用 fsockopen 连接到 WebSocket 服务器
Can't connect to WebSocket server with fsockopen
请帮助我将 WebSocket 连接到 php。
我尝试了这个代码,但是我收到了 400 Bad Request
$fp = fsockopen("cs.money", 443, $errno, $errstr, 30);
if (!$fp)
{
echo "$errstr ($errno)<br />n";
}
else
{
$out = "GET / HTTP/1.1rnrn";
///Send data
fwrite($fp, $out);
///Receive data - in small chunks :)
while (!feof($fp))
{
echo fgets($fp, 128);
}
fclose($fp);
}
我用js解决了我的问题
var WebSocket = require('ws');
var ws = new WebSocket('wss://cs.money/ws');
请帮助我将 WebSocket 连接到 php。
我尝试了这个代码,但是我收到了 400 Bad Request
$fp = fsockopen("cs.money", 443, $errno, $errstr, 30);
if (!$fp)
{
echo "$errstr ($errno)<br />n";
}
else
{
$out = "GET / HTTP/1.1rnrn";
///Send data
fwrite($fp, $out);
///Receive data - in small chunks :)
while (!feof($fp))
{
echo fgets($fp, 128);
}
fclose($fp);
}
我用js解决了我的问题
var WebSocket = require('ws');
var ws = new WebSocket('wss://cs.money/ws');