Erlang/OTP Forums

Author Message

<  Open Telecom Platform (OTP)  ~  gen_server:call call inside receive end block

dmitryme
Posted: Tue Jul 28, 2009 6:42 pm Reply with quote
Joined: 21 Jan 2009 Posts: 3 Location: Russia
Is it possible to call get_server:call({global, some_reg_process}, some_data) inside client spawn receive end block loop. E.g.:

Code:

start() ->
   register(client, spawn(?MODULE, loop, []),
   client ! hello.

loop() ->
   receive
     hello -> Res = gen_server:call({global, some_server}, hello),
                    io:format("~p~n", [Res]),
                    loop();
     stop -> unregister(client)
   end.

Server is very simple:
Code:

handle_call(hello, {Pid, _}, State) ->
   {reply, hello_response, State}.


My client silently die, w/o any error. At least I don't see any registered process as 'client'. If send hello not from spawned process all work fine. Client and server run on different computers.
[/code]
View user's profile Send private message MSN Messenger ICQ Number
Michal Ptaszek
Posted: Fri Aug 07, 2009 1:37 pm Reply with quote
User Joined: 01 May 2008 Posts: 35 Location: Krakow
Do your nodes see one another?

Check if you have your server node among nodes() at the client node (if not, check if the nodes share the same cookie set and try to connect them by invoking net_adm:ping(server_node@some_host)).
View user's profile Send private message
Mazen
Posted: Mon Aug 10, 2009 5:56 am Reply with quote
User Joined: 20 Jul 2006 Posts: 164 Location: London
Tip:
It helps if you use spawn_link and do application:start(sasl). It will give you more information.

You should also return the Pid of the process you spawn and then do erlang:is_process_alive/1 and erlang:process_info/1 to get more info about the process you spawned. Also try erlang:whereis(RegisteredName). where RegisteredName in your case would be: client

if you want to trace the messages that the process receive then do the following in the shell after you get the pid:

Code:

dbg:tracer().
dbg:p(Pid, [r]).


this will give you all traces on incoming messages to the process Pid (see http://www.erlang.org/doc/man/dbg.html function p/2). You can turn it of by calling

Code:

dbg:ctp().


Also make sure that loop/0 in your module is exported.

Anyway.... to answer your original question: Yes, you can do gen_server:call/2 in a receive statement.

Good luck.

/Mazz
View user's profile Send private message
baryluk
Posted: Tue Aug 18, 2009 10:11 am Reply with quote
User Joined: 05 Aug 2009 Posts: 48
If you are registering as {global, atom()}, remember to have nodes see each other, befor you are starting gen_server.
View user's profile Send private message
wuji
Posted: Tue Sep 11, 2012 3:39 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
H.W. Bush, and mother, Barbara Bush, officially endorsed Mitt Romney five weeks weeks cheap Ralph Lauren weeks ago. His brother, former Florida Gov. Jeb Bush, also has backed
presumptive Republican nominee.So far, George W. Bush has not.And while the former former [h3]cheap replica *beep*[/h3] former president is expected to formally support Romney at some point between
and Election Day -- perhaps in a written statement -- many Republicans Republicans cheap jordan shoes Republicans doubt he will actively campaign for the party's ticket this fall.His
from the political stage stands in contrast to his predecessor, former President President [h4]cheap Ralph Lauren[/h4] President Bill Clinton, who has plunged into campaigns large and small since
office, even a race for a state Senate seat in Buffalo, N.Y.At N.Y.At [h4]cheap designer *beep*[/h4] N.Y.At a similar point in his post-presidency, Clinton tried to sway the
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum