JS Client gets Connection Error 1006 when TLS enabled with Laravel + Ratchet PHP

  laravel, php, ratchet, reactphp, ssl

I am running a Ratchet server in my laravel app and the websocket works well in the default configuration as described in the ratchet documentation but when I try to enable TLS using ReactPHP’s SecureServer, I am unable to connect to the WebSocket server. Here is the code I am using for the TLS-enabled version:

$server = new HttpServer(
            new WsServer(
                new $controller(config('app.debug')) // Controller that implements MessageComponentInterface
            )
        );

        $loop = Loop::get();

        $secure_websockets = new Server('0.0.0.0:'.$port, $loop);
        $secure_websockets = new SecureServer($secure_websockets, $loop, [
            'local_cert' => config('websockets.cert'),
            'local_pk' => config('websockets.key'),
            'verify_peer' => false
        ]);

        $secure_websockets_server = new IoServer($server, $secure_websockets, $loop);
        $secure_websockets_server->run();

And for the version that works (but without TLS), this is the code that I am using:

$server = IoServer::factory(
            new HttpServer(
                new WsServer(
                    new WebSocketController()
                )
            ),
            $port,
        );
        $server->run();

The cert file contains the ‘—–BEGIN PUBLIC KEY—–‘ section and the key file contains the ‘—–BEGIN RSA PRIVATE KEY—–‘ section. Both files were generated using OpenSSL RSA 2048.

Source: Laravel

Leave a Reply