[erlang-questions] spawn_link

Thilani Abeysinghe a.thilani@REDACTED
Mon Dec 29 12:03:57 CET 2008


I have a problem of how to get the return value of a function when

spawn_link(Fun) ->pid() is used.

Im going to use above function in following manner.

init([]) ->

ChildPid = erlang:spawn_link(?MODULE, connect_to_server, [Ip,Port, ConId,
self(),State]).

connect_to_server(Ip, Port, ConId, ParentPid,State) ->
  case Result= gen_tcp:connect(Ip, Port,
  [binary, {packet, 0}]) of
  {ok, Socket} ->
           io:format("Socket Received:~w~n",[Socket]),
          ok =(catch gen_server:call(g_srv, {add_conn, self(), ConId,
Socket})),
          NewState = State#state{socket= Socket};
  {error, Reason} ->
          io:format("connection error host Ip:~w Port: ~w ~w ~n",
[Ip,Port,Reason]) ,
         connect_to_server(Ip, Port, ConId, ParentPid,State)
  end.

 I want to get the return value of connect_to_server function. How can I do
that.

Regards

Thilani
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081229/7f9170b9/attachment.htm>


More information about the erlang-questions mailing list