Abstraction for serverside connections

I’m currently doing some Client/Server stuff.

I’m in the early stage of development and do currently use gen_tcp on the server side directly, accepting connections in a single supervised Task which “loops” infinetly and does not have any means of shuting it down, except for a brutal kill.

Once a client connects, a GenServer is started under a DynamicSupervisor and ownership of the connection transfered to that GenServer.

In general this seems to work so far, but I have not even implemented handshaking (properly) and I already think, that GenServer was the wrong choice and that I should use a GenStatem perhaps?

But while looking into this I found that there is at least one client side library available that abstracts some connection and state handling away as far as I was able to see, so now my question is, is there some package available that abstracts manual accepting, spawning, etc away for me, such that I can focus on implementing (and defining) the actual protocol?

1 Like

Does Ranch sound like what you need? https://github.com/ninenines/ranch

3 Likes

Thanks for the hint, I’ve heard about ranch before but always thought it were for short lived connections only. After reading some guides it seems to be exactly what I’m looking for. I’ll further evaluate it in the next days.

2 Likes

Just for anyone curious, ranch is the tcp connector library used by cowboy, which is the http server that plug/phoenix use. ^.^

2 Likes