[erlang-questions] Stateful gen_servers

David King <>
Sun Oct 7 03:45:17 CEST 2007

> I would like to use gen_server to develop a stateful server, and  
> since gen_servers are  generally communicated using module:function 
> (arg) syntax, what's the best way to use them as stateful servers  
> per client, i.e., each for each client a gen_server is started and  
> is terminated when client asks explicitly or when client is  
> terminated. Thanks.

You could have each client do something like:

my_server:eat_cookie(Session,Cookie), [...]

Then in the server, the State field could have a dict of Sessions  
(generated via make_ref()?) to state information

If that's not enough, I have a tictactoe server that I wrote recently  
that maintains the states of games this way, so let me know if you  
want some live code that does this

More information about the erlang-questions mailing list