Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS Client gets Connection Error 1006 when TLS enabled #893

Open
apoorvpal01 opened this issue Jul 22, 2021 · 1 comment
Open

JS Client gets Connection Error 1006 when TLS enabled #893

apoorvpal01 opened this issue Jul 22, 2021 · 1 comment

Comments

@apoorvpal01
Copy link

apoorvpal01 commented Jul 22, 2021

Hey,

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.

@joaquin-gs
Copy link

In my case, the websocket server does not run. It throws this error message:

Error

Object of class React\Socket\SecureServer could not be converted to string

at D:\web\app\ssa\vendor\cboden\ratchet\src\Ratchet\Server\IoServer.php:59
55▕ * @return IoServer
56▕ */
57▕ public static function factory(MessageComponentInterface $component, $port = 80, $address = '0.0.0.0') {
58▕ $loop = LoopFactory::create();
➜ 59▕ $socket = new Reactor($address . ':' . $port, $loop);
60▕
61▕ return new static($component, $socket, $loop);
62▕ }
63▕

1 D:\web\app\ssa\app\Console\Commands\WebSocketServer.php:60
Ratchet\Server\IoServer::factory(Object(Ratchet\Http\HttpServer), Object(React\Socket\SecureServer))

2 D:\web\app\ssa\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:36
App\Console\Commands\WebSocketServer::handle()

And this is my code:

   public function handle()
   {
      $loop = Factory::create();
      $webSock = new Server('0.0.0.0:8443', $loop);
      $socketServer = new SecureServer(
         $webSock, 
         $loop, 
         [ 'local_cert' => 'certificate.crt',
            'local_pk' => 'private.key',
            'allow_self_signed' => true, 
            'verify_peer' => false
         ]
      );
      $server = IoServer::factory(new HttpServer(new WsServer(new WebSocketController())), $socketServer);
      $server->run();
   }

I am using Microsoft Windows 10, Laravel 8, PHP 7.4, cboden/ratched 0.4.3, WAMP server 3.2.0

Any help on this, anyone??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants