136 Replies
Project ID:
N/A
N/A
well well well, look what sock the cat dragged in
lmao
so you know websockets module right?
https://gist.github.com/stefanotorresi/bfb9716f73f172ac4439436456a96d6f
Might be a bit out of date but this should be a good read through to work out how it works.
Gist
Playing with Python asyncio and websockets
Playing with Python asyncio and websockets. GitHub Gist: instantly share code, notes, and snippets.
If you still need help after that feel free to ask questions.
i do not
i am not a python dev
ok
same here. I just help maintain a few python projects.
ive done websockets in other languaes, so i might not be as usefull as luna, but i still know some stuff
Yeah most of my knowledge is in node but websockets are the same at the end of the day no matter the language. Hopefully that gist helps with the syntax.
websockets ๐
<wss://utilities.up.railway.app/ws>
free clock
wss?
websockets over https = wss
oh
okay
or is it websockets with tls, idk you get the point
Same diff.
real
would an everytime sending realtime movement and stuff thing would be better or one that only sends if it changes, first one is good when the person has bad internet and data still gets processed
have a minimum tick time when nothing updates, but also send constantly when positions update? best of both worlds
that way you dont use server resources streaming the same data to the clients as fast as your code can
websockets.exceptions.ConnectionClosedOK: received 1000 (OK); then sent 1000 (OK)
๐
Whatโs the question?
that's not a question
after sending the message to the websocket server i get this error
Gonna need more than that. Code sample?
Sounds like the connection was opened and then closed?
one sec
code block
Just a tip at the start use three backticks and then py to make it highlight as python.
you instantly close the connection
hm
so its not blocking?
i thought client.recv is blocking
i just remove it then
i mean
the if statement
no, you are closing the connection once data is received
oh
else: client.close
i forgot to use while loop
nvm
yes
i thought its gonna block
now fixed
thanks
going very good
glad to hear it
server done, i think i can host it on railway rn
now i just need to make client work for it
see, a websocket implantation was super easy
hopefully it will pay out too with the performance because if it doesnt i am lost
if theres performance issues, it would 100% be on you, not the protocol
ah
forgot to delete the port env variable
restart works?
werent their issues with it or smth?
nvm
what
it auto redeployed it
restart on a service deployment but it auto redeployed it so doesnt matter
lets see if it works...
it worked its using memory again but still not a cpu lol
i got charged $0.0001 out of my free
railway remove free credit when
no no pls no lol
it would be such a shame if the good actors had to pay their 1-4$ usage
now i just unlock developer plan and it will be very good
finally, i just went instant for dev without a second thought when i first signed up
checking on usage
one sec
ah why its using even a gb of memory?
don't look at that, that data is unreliable, use the metrics graphs in the service
or is memory calculated from fractions too?
ok
it's a display bug that they haven't fixed in months
brody
then how?
there you go
the metrics graphs in the service itself is accurate, the graphs in the account usage are not accurate, use graphs in the service
it's purely a display bug, you won't be charged for 1gb
then how do i know billing?
ah okay
the price estimates should still be relatively accurate, but of course they are only estimates
bruh
lolololol
it will climb
atleast it works now, i just need to rework and hopefully it will have good performance
hopefully you wrote efficient code
yes lol
one last thing, can you explain what are these Layers and what are their point and how do they work? i never see something like this before
i know i am maybe stupid and i just dont know these
layers?
when you do railway up
it sends data to those layers or something
idk what you are talking about
i heard about deployment layer and network layer
show example
for example:
"Deployment Layer"
it just means the part of railways infrastructure that handles the deployments
this?
that's just pushing the image to railways container registry's so that their orchestrator can run the image
ok
@ImLunaHey just one simple question
i am using async for the server can i use threading for the client?
it would be easier cause i didnt mean to use async everytime
and my code is not formatted like async
I'd suggest reading https://stackoverflow.com/a/70920890 and the other answers on this page.
this is a python specific question and im not that great at python
ok
websockets actually fast on localhost, lets try on railway
everything is fast on localhost ik but i didnt expect web stuff to do well
I appreciate the help sock, but if you are going to help you gotta dumb it down for people
lol this is my own ticket, you
yes I know it is, I'm talking about when you go into other peoples help threads
oh ok
Not sure if I can bump this or not, but I'm not sure what uri to use for the client to send to
would it just be
wss:railway-name.up.railway.app:PORT
?
Ah, I believe it's wss:railway-name.up.railway.app/ws
if your endpoint is
/ws
then you would access it over wss://railway-name.up.railway.app/ws
How would I configure/see the end point? Normally I thought it would be
:PORT
endpoint = the path that you have setup in your code to handle the websocket connection, the endpoint doesnt have anything to do with PORT
in this case, I believe I'm using localhost
what route does that handle the websocket connections on
Not sure
find out
Forgive me, but I'm not sure what you mean by route
I'm trying to setup a simple script (so it's just server.py right now) to test websockets with Railway
route / endpoint / path
same thing
test-production-6637.up.railway.app ?
Ethann
sock, you handle this, i will judge you tho
set a subdomain in the service settings
:o
okay stop
Lol
Custom domain?
the first thing you said was wrong
no, dont listen to what he just said
Hahaha okay
sock, do you want to try again? ethan needs to tell us the endpoint that this code will accept websocket conns on
Wait, do I have to setup something with flask or django
That kinda route?
Right now, it's just a python script
Was hoping I didn't have to touch flask
sock, do you use flask?
bruh that was a yes or no lol
Yes i used flask before, but he is using websockets so i dont know what flask has to do with this.
no if you want just simple sockets but on the web you can use normal websockets
Use readthedocs.io for the docs
It has tutorials
you are not too good at helping
Well the script I'm using is pretty much lifted off the starter docs
The host should be 0.0.0.0 and port should be os.environ['PORT'] for the server on railway but you need to import os module for it.
._.
From what I read, PORT doesn't have to be configured
And I thought 0.0.0.0 is the same as localhost
yes it is i didnt know if you are already using it
it is automatically set to a port that is automatically forwarded to your subdomain.up.railway.app website with ssl
If you dont set it in service environment variables it will forward and will work
its not
its very much not
Then just use 0.0.0.0
you can just use wss://subdomain.up.railway.app:443 for connecting on client after this and it has ssl configured
I go now so i dont say anything stupid, Brody continue
or wait for answer
using wss implies port 443
this will run on railway
once running on railway you will connect it to with
wss://subdomain.up.railway.app
So if I had set PORT to 8765, then that works as well,right?
remove that
you dont need to specify a PORT in your service variables with the code i provided
Okay awesome
Why is that though? Just because the default is 443 for wss?
railway will generate a PORT for you
Okay, then using
looks like it might work
Well perhaps I'm doing something wrong, but I see no output in the deploy section
No errors either
do you have a repo?
yes
send it over
GitHub
GitHub - Ethan0429/test: test
test. Contribute to Ethan0429/test development by creating an account on GitHub.
Oh! Error output finally:
Okay so it's receiving, but it fails on websocket.send from the server
I'm assuming it's failing bc I don't have 2-way channel? Although I though that's what a socket was lmao.
I only need the client to send data to the server
hold your horse
delete your Dockerfile
rename
test.py
to main.py
add a requirements.txt
file with the needed dependencyshahaha okay okay
Alright, still nothing
Im getting this though
running websocket server on port 6939
yeah thats normal
GOT IT
had to use /ws
at the end
sorry if you specified that already
Thank you so much for the spoonfeed
lmao
spoonfeed
no worries, we all start somewhere
btw if you ever get this error again it means that the connection got closed like when you use a with statement and it ends