Websocket connection to server fails
In my client I am seeing an error "WebSocket connection to 'ws:3.12.219.195' failed". Is this something to worry about? Do I need to ensure a websocket port is open?
5 Replies
Hi @cmilazzo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, a failure in WebSocket connection can be problematic as it may prevent real-time communication between the client and the server. Wasp provides a fully integrated WebSocket experience by utilizing Socket.IO on the client and server. It automatically handles URL setup, CORS, and establishes a WebSocket connection from the client to the server by default.
However, if you have set
autoConnect: false
in your Wasp file, you will need to explicitly call socket.connect()
or socket.disconnect()
as needed.
Here is how you can enable WebSockets in your Wasp file:
If the issue persists, it might be unique to your setup or machine. You might want to check your network settings and ensure that the WebSocket port is open and properly configured.
For more information, you can refer to the Wasp WebSocket documentation (https://wasp-lang.dev/docs/advanced/web-sockets).
Sources:
- Wasp WebSocket Documentation (https://wasp-lang.dev/docs/advanced/web-sockets)
- Wasp Discord Support Thread (https://discord.com/channels/686873244791210014/1213427624433680455)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------- Is this happening locally or on a server?
- Are you trying to run the app in production by running
wasp start
?
- Are you using the WebSockets feature or not?I don't actually use the websocket feature, although I created the app using Mage, so it could have been inserted. This is on a linux server, and yes I'm running using wasp start.
wasp start
is not meant for deployment / production usage. If you are developing using wasp start
, that's okay - but when the time comes to go "live", you should build your app and deploy the built artefacts. Some more details here: https://wasp-lang.dev/docs/advanced/deployment/manually
The websocket error you are seeing is related to the development hot reload server which enables quicker UI refreshes when you are developing your app. This development server starts with wasp start
, it won't start when you build your app with wasp build
.Deploying Manually | Wasp
This document explains how to build and prepare your Wasp app for deployment.
That explains that error. Unfortunately the manual deployment instructions don't work for a plain linux machine. I'll have to go figure out that process I guess.
What is it about wasp start that makes it unsuitable for a production server BTW?