Error 502 on python WebSocket

Hey, so basically I’m running a flask app at 0.0.0.0:8080 in the main code, but in a thread, I’m running a websocket along with it, at os.environ[“PORT”] which is 3000.

But when I try to connect to it using a python test client, it gives me the error 502:
server rejected WebSocket connection: HTTP 502

I am not sure why this is happening.

You only get one port to expose services on, so Flask will have to run on whatever the environment PORT value is, too.

Having said that, note that Glitch is shutting down project hosting in July, so this may not be the best time to start a new project.

its not a new project, its a project i’ve been relying on glitch for, since like last november.

also, wont i get a error like “port already occupied”?
also, didnt know i was supposed to run flask on the env PORT aswell, cuz i was using 8080 and it somehow worked.

If you want to access it from the outside on the implicit port 80, then it needs to use the environment PORT variable (that’s the only port forward that’s built in). If you’ve been accessing it explicitly on port 8080 then that may have worked.

As for the error, you’ll get that when two services are trying to use the same port, e.g. you’re running Flask as well as a completely unrelated server both on port 3000. Websockets start life as an HTTP call, so if you want Flask and websockets, you probably want flask-socketio so everything runs through the same server instead of separate servers.

uh okay, so you say that the only real solution if i want both the flask and websocket on one project/server, is flask-socketio?
okay…

That’s the only real solution I know of if you’re running a Flask server.

okay then
thanks for your help