Thanks for quick reply.:)<br>function connect_to_server method tries to connect to a server, when it connects sucessfull it returns<br>{ok,Socket}.<br>so I want to get that socket and send messages to the server. So here I'm trieng to save the socket value in <br>
state of gen_server.<br>regards <br>Thilani <br><br><br><div class="gmail_quote">On Mon, Dec 29, 2008 at 4:40 PM, Chandru <span dir="ltr"><<a href="mailto:chandrashekhar.mullaparthi@gmail.com">chandrashekhar.mullaparthi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">2008/12/29 Thilani Abeysinghe <<a href="mailto:a.thilani@gmail.com">a.thilani@gmail.com</a>>:<br>
<div><div class="Wj3C7c">> I have a problem of how to get the return value of a function when<br>
><br>
> spawn_link(Fun) ->pid() is used.<br>
><br>
> Im going to use above function in following manner.<br>
><br>
> init([]) -><br>
><br>
> ChildPid = erlang:spawn_link(?MODULE, connect_to_server, [Ip,Port, ConId,<br>
> self(),State]).<br>
><br>
> connect_to_server(Ip, Port, ConId, ParentPid,State) -><br>
> case Result= gen_tcp:connect(Ip, Port,<br>
> [binary, {packet, 0}]) of<br>
> {ok, Socket} -><br>
> io:format("Socket Received:~w~n",[Socket]),<br>
> ok =(catch gen_server:call(g_srv, {add_conn, self(), ConId,<br>
> Socket})),<br>
> NewState = State#state{socket= Socket};<br>
> {error, Reason} -><br>
> io:format("connection error host Ip:~w Port: ~w ~w ~n",<br>
> [Ip,Port,Reason]) ,<br>
> connect_to_server(Ip, Port, ConId, ParentPid,State)<br>
> end.<br>
><br>
> I want to get the return value of connect_to_server function. How can I do<br>
> that.<br>
><br>
<br>
</div></div>I'm assuming you want to send intermediate results, as<br>
connect_to_server seems to be part of a process which is long lived.<br>
In such cases, send a message to the parent process from the spawned<br>
process.<br>
<br>
cheers<br>
<font color="#888888">Chandru<br>
</font></blockquote></div><br>