我一直在尝试让 ReactPHP 套接字启动并运行一段时间,一旦启动,我可以在指定的端口上远程登录它,但我不能使用 websocat 或任何 js lib 通过 ws:// 协议进行连接。任何帮助,将不胜感激。
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server('127.0.0.1:8000', $loop);
$socket->on('connection', function(ConnectionInterface $connection) use ($colors) {
$connection->write("Hello " . $connection->getRemoteAddress() . "!\n");
$connection->on('data', function($data) use ($connection){
$connection->write('received: ' . strtoupper($data));
});
});
echo "Listening on {$socket->getAddress()}\n";
$loop->run();
服务器:
Listening on tcp://127.0.0.1:8000
客户:
websocat ws://localhost:8000
websocat: WebSocketError: HTTP failure
websocat: error running