Help with websocket/multiplayer on glitch errors

I’ve been playing around with websockets and have gotten some projects to work with them, but this specific project doesn’t seem to work on Glitch. It works perfectly fine when I localhost, but the same code doesn’t work on Glitch. I’m assuming it’s something with Glitch limiting the environment, something with specific localhost code on the Glitch environment.

Looking at the console on the app, I’m getting this error which looks like an issue with the localhost/glitch site.
GET http://localhost:8000/socket.io/?EIO=3&transport=polling&t=NbCXl7s net::ERR_CONNECTION_REFUSED

There aren’t any errors in the code console, but it doesn’t log when someone connects if that narrows it down anymore.

Code here: Glitch :・゚✧
Site here: https://sepia-nasal-chill.glitch.me

I’m not super familiar with websockets yet, so please be patient with me. Thanks in advance!

Hi, could you try listening on process.env.PORT rather than 8000? Glitch only supports port 3000, and sometimes another one if you’re in the debugger.
Edit: you should also be connecting to https://sepia-nasal-chill.glitch.me rather than http://localhost:8000 in public/sketch.js - I’m not overly familar with socket.io but that should work.

I just made those changes and it doesn’t seem to be throwing those errors anymore, but it still isn’t recognising the connections. Is it something with the ports still, because I’m using "https://sepia-nasal-chill.glitch.me:3000" and not something like "https://sepia-nasal-chill.glitch.me:"+process.env.PORT?

EDIT: New error: GET https://sepia-nasal-chill.glitch.me:3000/socket.io/?EIO=3&transport=polling&t=NbC_UHj net::ERR_TIMED_OUT

You can get rid of the :3000 on the end of the url - glitch automatically forwards your app to the correct port and specifying a port won’t work :slight_smile:
Hopefully that should fix that problem :crossed_fingers:

1 Like


Seeing these errors, something with the server now I’m guessing? Thanks for that last bit of advice, I wasn’t aware of that forwarding.

Any server logs?

Sorry, how do I get to those?

Tools > Logs

Oh that, sorry. Only that the server is running – The server is now running at https://sepia-nasal-chill.glitch.me:3000

Take a look at the SocketIO compatibility chart:

It looks like you are using server version 4.0.2 and client version 2.1.1 which aren’t compatible with one another out of the box.

3 Likes

Thank you so much! Updating the client version worked perfectly. Looks like the code I was basing this off of was old and had a lower server version, and when I cloned it to Glitch, the server version updated through the package.json file but the client version needed to be updated to match that.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.