scotchegg's avatar

Reverb works via http but not using ws. 404 Page?

Hey !

If anyone has any spare time or knowledge I would be really gratefull for help here.

I have what appears to be a working laravel 11 / Reverb server on my WSL2 ubuntu server running on windows 11. When i access the website http://reverb-chat.local:8082/ it all works as expected.

However i want to push data into without accessing from a website. To test my server/socket connection I run

wscat -c ws://172.18.37.8:9090 from windows which gives me the error: Unexpected server response: 404 When test the connection by using invalid ports I get ECONNREFUSED 172.18.37.8:9091 so the ports are working ok, so i believe there are no issues crossing to WSL from windows.

It seems like something else is going on or i am missing a step. I also tried adding the app id as wscat -c ws://172.18.37.8:9090/app/646099 Then i get a brief success and disconnect message

Connected (press CTRL+C to quit) < {"event":"pusher:error","data":"{"code":4001,"message":"Application does not exist"}"} Disconnected (code: 1006, reason: "")

  1. Am i right i need to pass the App id to get a connection?
  2. Is this a red hearing and something else is going on I am not aware of?

My env variables are all correct, i start the server with php artisan reverb:start --host=172.18.37.8 --port=9090 --debug

Where IP 172 etc is my WSL IP.

Thanks for any help or steer here. All i can find are working reverb examples via websites and nothing as a web faceless server so to speak.

0 likes
7 replies
LaryAI's avatar
Level 58

To address the issue you're facing with connecting to your Reverb server via WebSocket, let's break down the problem and provide a solution step-by-step.

Step 1: Verify Reverb Server Configuration

Ensure that your Reverb server is correctly configured and running. You mentioned starting the server with the following command:

php artisan reverb:start --host=172.18.37.8 --port=9090 --debug

Make sure that the server is indeed running and listening on the specified IP and port.

Step 2: Check WebSocket Route Configuration

Ensure that your WebSocket routes are correctly set up in your Laravel application. Typically, you would define WebSocket routes in a websockets.php configuration file or similar. Verify that the routes are correctly pointing to the Reverb server.

Step 3: Verify Environment Variables

Double-check your .env file to ensure that all necessary environment variables for Reverb are correctly set. For example:

REVERB_APP_ID=your_app_id
REVERB_KEY=your_key
REVERB_SECRET=your_secret
REVERB_HOST=172.18.37.8
REVERB_PORT=9090

Step 4: Test WebSocket Connection

Use wscat to test the WebSocket connection. Based on your description, it seems like you are trying to connect without specifying the app ID, which might be causing the issue. Try connecting with the app ID as follows:

wscat -c ws://172.18.37.8:9090/app/your_app_id

Replace your_app_id with the actual app ID from your Reverb configuration.

Step 5: Debugging

If you still encounter issues, enable debugging to get more detailed logs. You can do this by adding the --debug flag when starting the Reverb server, which you already did. Check the logs for any errors or warnings that might give you more insight into what is going wrong.

Example Code

Here is an example of how you might configure your WebSocket routes and environment variables:

websockets.php (Configuration File)

return [
    'app_id' => env('REVERB_APP_ID'),
    'key' => env('REVERB_KEY'),
    'secret' => env('REVERB_SECRET'),
    'host' => env('REVERB_HOST', '127.0.0.1'),
    'port' => env('REVERB_PORT', 6001),
    'debug' => env('REVERB_DEBUG', false),
];

.env (Environment Variables)

REVERB_APP_ID=your_app_id
REVERB_KEY=your_key
REVERB_SECRET=your_secret
REVERB_HOST=172.18.37.8
REVERB_PORT=9090
REVERB_DEBUG=true

Conclusion

By ensuring that your Reverb server is correctly configured, your environment variables are set, and you are connecting with the correct app ID, you should be able to resolve the 404 error and establish a successful WebSocket connection. If the problem persists, check the server logs for more detailed error messages that can help you diagnose the issue further.

scotchegg's avatar
scotchegg
OP
Best Answer
Level 2

I think I have solved it. you dont pass the app ID, you pass the REVERB_APP_KEY wscat -c ws://172.18.37.8:9090/app/REVERB_APP_KEY

4 likes
thangnm's avatar

@scotchegg Thank you, it works. How sensitive is the Reverb_App_Key? Since the client application (my case is a mobile app) is required to send REVERB_APP_KEY to establish connection to Reverb, is it ok to store at client side (mobile app)?

ctechdev's avatar

@thangnm I'm trying to connect from my app in Flutter now and I can confirm that the connection is successful with ws://localhost:8080/app/{{REVERB_APP_KEY}}

ctechdev's avatar

I have just started trying to use reverb, I would like to implement a chat on my mobile ppa in flutter. Can you give me some initial suggestions to test the connection to rever also with Postman. I can't figure out how to properly configure the connection for the client. I see this correctly Starting server on 0.0.0.0:8080 (localhost). Thanks in advance

Please or to participate in this conversation.