Fork me on GitHub
#other-languages
<
2022-02-23
>
Stuart12:02:38

Anyone worked with websockets in golang ? I want to have a central hub, and have multiple clients connect over websockets so the clients can be sent commands. As I understand it, even with gorilla, I need to manage keeping track of who is connected and the routing myself? i.e. On connection, I'll send client name in the request, then I can keep a hashmap keyed on name and value of the websocket connection. Then I have to ping / pong messages essentially saying "I'm alive", then have a goroutine in the background check when the last ping was received from each client, and remove them from the map. DOes this sound right? Anyone used any good packages that manage most of this for me ?

hiredman19:02:14

not go specific, but I've worked with websockets some, and I would, if possible, listen to the state of the underlying tcp connection, and go off that being open or closed, secondly use websockets built in ping frames, and maybe thirdly do by application level ping pong

hiredman19:02:57

we use a framework at work that does something like this, it does its own ping/pongs, and keeps a map of uuids to websocket connections, but we found that it leaked, so we ended up with our own background thread that goes through the map from time to time and checks the state of the tcp connection and removes things as neeed

Stuart12:02:37

My scenario is a central hub that exposes a couple of http endpoints, and itself is connected to rabbitmq. It will receive commands down its rabbitMQ queue and will want to do some routing of the commands out to the correct clients.

Stuart12:02:57

the client themselves are on machines with no internet out, so we need to talk to them via this central hub