<div dir="ltr">The gen_server can start a tcp server and then call gen_fsm:start_link/3 in the init callback and put the PID from the result {ok, PID} in state. As things come through the tcp in gen_server, you can use gen_fsm:sync_send_event/3 to send the event to the gen_fsm and it will reply to tell the gen_server what to do and the gen_fsm will keep track of state.<br>
<br>If the gen_fsm dies, the gen_server will be restarted as well, unless you put process_flag(trap_exit, true) in the init callback.<br><br><div class="gmail_quote">On Thu, Aug 28, 2008 at 3:46 AM, Christian Czura <span dir="ltr"><<a href="mailto:christian.czura@gmail.com">christian.czura@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br>
it's a little bit hard for me to grasp how to plug together gen_servers<br>
and gen_fsms that belong to the same service or operation.<br>
<br>
For example, Joe shows[1] how to abstract away the protocol of a<br>
webserver, so you end up having three processes[2]:<br>
server <-> some_protocol <-> tcp/udp<br>
I would write the server-process as a gen_server and the<br>
protocol-process as a gen_fsm.<br>
<br>
Now I wonder how/where to start the protocol-process from the server:<br>
Would I start it from the server's init function and save its pid in the<br>
server's state?<br>
<br>
Or would I start both the server and the protocol-process via the<br>
supervisor / supervision strategy?<br>
If so, how does the server know about the protocol-process? It's obvious<br>
that the protocol-process's pid needs to be passed along somehow to the<br>
server.<br>
<br>
You might have noticed that I'm not sure when to use a supervision<br>
strategy or when to spawn a process from within a process that is<br>
supervised. That is because I don't know how/if it's possible in a<br>
supervision strategy to pass along the pid of one process to another.<br>
{M,F,A} in the childspec comes to mind, but how do I get the pid of<br>
another process in the same childspec, and is this the right way of<br>
doing things?<br>
<br>
If you know any other helpful code example, feel free to post the link. :-)<br>
<br>
Links:<br>
[1]: <a href="http://www.sics.se/%7Ejoe/tutorials/web_server/web_server.html" target="_blank">http://www.sics.se/~joe/tutorials/web_server/web_server.html</a><br>
[2]: <a href="http://www.sics.se/%7Ejoe/tutorials/web_server/web_server.jpg" target="_blank">http://www.sics.se/~joe/tutorials/web_server/web_server.jpg</a><br>
<br>
Thanks,<br>
Chris<br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br></div>