Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to structure an Erlang OTP UDP server
    primarykey
    data
    text
    <p>I am just reading <em>Manning's Erlang &amp; OTP In Action</em>. Very good book, I think. It contains a nice TCP server example but I'd like to write a UDP server. This is how I structured my app so far.</p> <pre><code>my_app % app behaviour |-- my_sup % root supervisor |-- my_server.erl % gen_server to open UDP connection and dispatch |-- my_worker_sup % simple_one_to_one supervisor to start workers |-- my_worker_server % gen_server worker </code></pre> <p>So, <code>my_app</code> starts <code>my_sup</code>, which in turn starts <code>my_worker_sup</code> and <code>my_server</code>. The UDP connection is opened in <code>my_server</code> in active mode such that <code>handle_info/2</code> is invoked on each new UDP message in response to which I call <code>my_worker_sup:start_child/2</code> to pass the message to a new worker process for processing. (The last call to <code>start_child/2</code> is in fact, as per the book's recommendation, wrapped in an API function to hide some of the details, but this is essentially what happens.)</p> <p>Am I suffering from OTP fever? Should the <code>my_worker_server</code> really implement the gen_server behaviour? Do I need <code>my_worker_sup</code> at all?</p> <p>I set it up in like this so that I can use <code>my_worker_sup</code> as a factory via the <code>start_child/2</code> call but I only use the worker's <code>init/1</code> and <code>handle_info(timeout,State)</code> functions to first setup state and then to process the message before shutting the worker down.</p> <p>Should I just spawn the worker directly? Is another behaviour better suited, perhaps?</p> <p>Thanks, HC</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload