Question

How do I use websockets on an app

I’m making a server with a DO app.

Websockets aren’t working (Firefox can’t establish a connection to the server)

Is it because of the port? How can I allow the port through? I tried making it 8080 (defined in my app spec as the http port), but that didn’t work. Tried making it a random port number, but that didn’t work either.

Are websockets blocked somehow? Do I need to allow the port somehow?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I’m having the same problem with a Droplet project. I’ve tried downloading the repository that njw suggested and modify it with no result. I’ve also done some experimenting with express-ws. It works locally, but I can’t deploy to the DigitalOcean server.

I get the “Firefox can’t establish a connection to the server” as well. Made me wonder if there’s some special combination of ip and port you should hit, and if it should be allowed in firewall, nginx, or similar.

Does anyone know how to fix it?

Take into account the “HTTP Request Route” that you’ve set up for your Web Service.

If your server exists at:

https://example.com/**API**

Your WebSocket connection now exists on the “API” namespace.

This means you will connect to your WebSocket server using:

was://example.com/api

If you’re using Socket.io you can read about it here: https://socket.io/docs/v4/namespaces/

Hey there!

Services that you run on the App Platform are exposed via app domains on port 443/HTTPS. So you should use the wss:// scheme when connecting. This is not necessarily the same port as you would specify that your service is listening on internally.

We have a sample nodejs repo that uses websockets and can be forked + deployed to the App Platform without any changes if that helps as a reference: https://github.com/snormore/sample-websocket

Hope that helps! Nate