beyondcode / laravel-websockets

Websockets for Laravel. Done right.
https://beyondco.de/docs/laravel-websockets
MIT License
5.07k stars 612 forks source link

failed: WebSocket is closed before the connection is established. #282

Closed periseas closed 4 years ago

periseas commented 4 years ago

I get the error: failed: WebSocket is closed before the connection is established.

image

I already checked many answers but I can't find the solution, I leave the codes.

websockets.php

image image

broadcasting.php

image

Bootstrap.js image

Note Already verify that port 6001 is open

kieuminhcanh commented 4 years ago

Please show your debug logs of websockets:serve

xlcrr commented 4 years ago

I'm getting the same error. Been stuck on this for weeks with Forge + nginx + AWS. Would love to see a new tutorial making this work

kiwo12345 commented 4 years ago

any news on this? I have the same problem

kieuminhcanh commented 4 years ago

Please show your debug logs of websockets:serve

Cello93 commented 4 years ago

verify that if you have the port open or you can enable it with, sudo iptables -A INPUT -p tcp -i eth0 --dport 6001 -j ACCEPT

r0bdiabl0 commented 4 years ago

I too am seeing this same error message. I am using Laravel Forge with a Digital Ocean instance. Latest Laravel 6 and PHP 7.4. I have opened up port 6001 on the server.

There are no debug logs of websocket:serve. It says:

Starting the WebSocket server on port 6001... but nothing else.

r0bdiabl0 commented 4 years ago

I downgraded to PHP 7.3 to try as well as 7.4 required the latest pusher/pusher-php-server v4. After downgrading to 7.3, I updated to latest pusher/pusher-php-server v3. That did not help either.

r0bdiabl0 commented 4 years ago

Ok, I think I solved the problem for myself and that this helps others. I am using Laravel Forge to provision the servers. I also use SSL option and Let's Encrypt. This automatically forces all traffic to use SSL. So when you are trying to connect to websockets, it's trying to connect over wss which is the secure url for websockets.

I didn't have websockets configured for SSL so it was denying the connection. Once I configured SSL for websockets, I was finally able to connect the dashboard successfully. For Forge, I just used the path's that it created for the Let's Encrypt certs and added them to the websockets configuration.

rennokki commented 3 years ago

For future reference, there might be a problem with the client: https://github.com/beyondcode/laravel-websockets/issues/510

mnuellas commented 3 years ago

Hi ! Sorry for re-opening old subjects, I also found a solution after reading r0bdiabl0's answer. If after configuring the ssl for your websockets and it stills not working try adding 'verify_peer' => false, to your config/websockets.php file in the ssl configuration. Worked for me