GJain
GJain

Reputation: 5093

Can a gen_server receive messages from two different client processes?

So 1 & 2 are sent by ServerPid and 3 is sent by ejabberd. This is working but I am not sure about the correct behavior. So,

My question is:

Please help.

Upvotes: 1

Views: 217

Answers (1)

7stud
7stud

Reputation: 48589

Any process that has the gen_server's pid can send the gen_server a message using !, which will be handled by the gen_server's function:

handl_info()

Any process that has the gen_server's pid can call the functions:

call(GenServerPid, Msg) 
cast(GenServerPid, Msg)

which will be handled by the gen_server functions:

handle_call() 
handle_cast() 

In elixir, there is a module called Agent, which is just a gen_server that stores State, like a counter. Multiple processes can update the counter and retrieve the current count. Of course, some process has to start the gen_server, then pass the pid to the other processes that want to update/retrieve the count.

Upvotes: 3

Related Questions