so, recently prime has been making doom in ascii and wants to make a web frontend for it, but because its over tcp, he cant.
the most scalable way of doing this is through cloudflare workers, and because cloudflare workers uses JS, prime doesnt want to use it.
luckily, cloudflare has a way of creating workers with rust, which prime loves for some reason. this article explains how to make a simple project with workers-rs and get started on a ws <-> tcp proxy
starting a cloudflare worker project with rust
this is thankfully very simple, you just have to cargo generate cloudflare/workers-rs
, this will give you some base code to work with.
using websockets with workers-rs
this part isnt as easy because there is barely any documentation on how to do it, but there is some test code found in the repo to do it with.
oh god its tcp time
this is the part that i assumed was going to be really bad with rust WASM bindings, but its suprisingly simple, there is still no documentation but there is some example code which just gives it all here
putting it all together
so, it was basically as simple as combining those 2 examples together, i've made a github repository to show how i did this, and stress tested it with 10,000 clients, it works pretty well!