[erlang-questions] Stateful gen_servers

shahzad bhatti bhatti_shahzad@REDACTED
Sun Oct 7 06:23:56 CEST 2007


Thanks David for the tip. I think I can use session-id to track state and have the client pass it with each request. Though, I would liked it if somehow that session-id is implicitly passed. Also, it would help if you can share a sample application.

David King <dking@REDACTED> wrote: > 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:

Session=my_server:logon(),
Cookie=my_server:get_cookie(Session),
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


       
---------------------------------
Moody friends. Drama queens. Your life? Nope! - their life, your story.
 Play Sims Stories at Yahoo! Games. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071006/7f8ef926/attachment.htm>


More information about the erlang-questions mailing list