Laravel-websockets: failed: WebSocket is closed before the connection is established.

Created on 4 Nov 2019  路  9Comments  路  Source: beyondcode/laravel-websockets

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

Most helpful comment

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.

All 9 comments

Please show your debug logs of websockets:serve

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

any news on this? I have the same problem

Please show your debug logs of websockets:serve

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

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.

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.

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.

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

Was this page helpful?
0 / 5 - 0 ratings