Hello guys! Could anybody please share some links ...
# ktor
z
Hello guys! Could anybody please share some links to good ktor websocket server tutorials? Gonna make a server for a mobile game. So need to have a look on best practice.
c
There’s a pretty good tutorial for getting starter https://ktor.io/docs/creating-web-socket-chat.html#what-s-next It definitely doesn’t demonstrate best practices, but does teach you all the fundamentals. Namely, that there’s no inherent connection between multiple clients, and you’ll need to build that out yourself. For a best practice when running websockets in production, you’ll just want to keep in mind that multiple clients might be connected to multiple server processes, so you won’t be able to store the game state in-memory as described in the ktor tutorial. You would need to store the game state in another observable system like Redis, so that all clients across all server processes will still see the same data and get updated in realtime. Redis has an example project showing how you might do this with Java/Spring Boot, which you should be able to translate to Ktor without too many changes https://github.com/redis-developer/basic-redis-chat-app-demo-java
c
Philip Lackner has a course on how to do this. He shows you how to do this while writing a “sketch” game. It uses XML for the views, but can easily be modified to use Compose for the views. His course on compose shows how this works. I wish google had courses like his. Both are paid courses but very worthwhile, imho. Clears up a lot of questions about how to setup games using ktor on the back and android on the front
👍 1
r
He has also a free one.

https://youtu.be/sKCCwl5lNBk?si=Kn1F9TyQavgx1BsL

👍 1