R
Railway

✋|help

Hello everyone, i'm trying to make a python websocket using websockets library also flask

Aa3lx08/22/2023
so basically i have this ->

async def main():
    url = os.environ.get('RAILWAY_URL', 'localhost')
    port = os.environ.get('RAILWAY_PORT')
    print(f"WebSocket server is running at: wss://{url}:{port}")
    asyncio.ensure_future(ping_pong())
    asyncio.ensure_future(websockets.serve(handle_connection, "0.0.0.0", 4505))

    app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 5000)))

asyncio.run(main())


functions functions etc....

when i go to my website hhr-bot-api.xyz i get the empty flask page but the thing is how do i connect to the websocket server? the railway terminal doesn't show anything out of common i used everything.
wss://hhr-bot-api.xyz:4505 / ....... nothing looks to work.
Bbrody1928/22/2023
you can't expose multiple ports, you need to have the websocket and http server listening on a single port
Aa3lx08/22/2023
okay i'll try this one. Thanks
Aa3lx08/22/2023
doesn't work either
Bbrody1928/22/2023
what doesn't work
Aa3lx08/22/2023
connecting to the websocket
the flask app works perfectly
Bbrody1928/22/2023
then that would be a code issue
Aa3lx08/22/2023
btw site -> https://hhr-bot-api.xyz/
i get no errors or anything else
Bbrody1928/22/2023
that's an issue too
Aa3lx08/22/2023
https://pastebin.com/f1vgQpw9
look by yourself ....
Bbrody1928/22/2023
unfortunately I'm not a python developer, so I'm not much help here, but I know for an absolute fact that this can be done
Aa3lx08/22/2023
oh
ty anyway then.
Jjonbeau8/22/2023
some things that might help,
you may consider using quart instead of flask: https://flask.palletsprojects.com/en/2.3.x/async-await/#when-to-use-quart-instead

i connect to my websocket like this (no port)
let host = window.location.hostname;
let socket = new WebSocket(`wss://${host}/ws/con`);


and it seems to be working, but im still in testing phases. a fetch interrupts this connection & that may be a problem with my code. in quart you can define a websocket route like this

@app.websocket('/ws/con')
async def websock():
  pass
Aa3lx08/23/2023
thanks, works now.

Looking for more? Join the community!

Recommended Posts
Extension of Payment Due Date for SubscriptionIs there a way I can request for a brief extension of a few days for my upcoming payment?Hello Everyone! I am facing some problem related to deploying my nodejs application.I have deployed my nodejs application using github, but do not know how can I connect phpmyadmin so RedeployHey there, is there away to start a redploy using the Railway APIKafka Connectioncould anyone help me setup kafka cluster? I've went through the deployment process but getting a conHosting a monorepo with a Vite/Svelte Front and and a Fiber BackendI am trying to host my monorepo application within railway however I am facing some issues when tryiUnexpected timeouts and slow downsHey guys! I'm writing this post since we've been experimenting some slow downs and timeouts during tconfigure variable in VM ARGUMENTSI would like to know how do I create a variable "VM Arguments" in the railway environment? currentluhmm i think i filled the entire disk somehowservice id: 66b587c8-3c50-4dd0-8dfa-394ade04a0eci want to deploy a wordpres, is it possible?project id fb928ae2-62f0-4f8f-be68-9f7902efbebdBilled per usage plan with carryoverHey guys, I'm currently on a usage based plan but my app is only projected to use $1.70/month. Will How to use the Kafka project?I'm relatively new to Kafka and I want to publish and consume events to the Kafka running in a kafkaCannot login to Railway.app this morningHere's what I'm doing to login: I go to railway.app, and select Login enter my email address and preRelative path issueI am trying to read some Json files and parse them with one of my services. Locally it works fine. Can't run Railway CLI down command with project tokenhey , it is possible to run the railway down command with railway project token without logging in. Ruby on Rails Deployment with database and redisi had a few questions about linking my database and redis server within railway app ... I tried but Lost all my 20$ credits out of no whereSo i just got an email saying my projects needs 3$ in credits, but suddenly when i check? my whole 2any reason why my usage suddenly jumps to 4GB when there are no tasks running?The app had no requests for for the entire day but the usage jumped, any reason why this could happei want to dowload my post gre db locallyhow can i dowload my post-gre db locallyCloudflare custom domain not workingI just upgraded the api for Cloudflare, but the custom domain is no longer workingError: Unsupported Gradle version: 8============== Using Nixpacks ============== context: 78ee202a04734b630f61d71bea3f81cd  Nixpacks