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.
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
Hopefully that should fix that problem
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.