0

I've been trying to get ReactPHP socket up and running for a bit now, once up, I can telnet to it on the specified port but I cannot use websocat or any js lib to connect via ws:// protocol. Any help would be appreciated.

    $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();

Server:

Listening on tcp://127.0.0.1:8000

Client:

websocat ws://localhost:8000
websocat: WebSocketError: HTTP failure
websocat: error running
Farid Anthony
  • 11
  • 1
  • 1

1 Answers1

1

For anyone struggle with this. React opens a low-level tcp socket which cannot be used with socket.io type ws:// connections. You will need to use a wrapper like Ratchet php.

Farid Anthony
  • 11
  • 1
  • 1