Erlang: when to perform `inets:start()`?

inets is a "stand-alone" Erlang application; inets:start() is just an alias to application:start(inets). I guess the answer pretty much depends on how you maintain your code.

If your code is packaged as an application, your .app file should list inets as required to be started before yours (see the applications tag). Starting your applicaion with application:start(my_app). will now ensure that inets is also started. Consequence: if you make a boot file, it will also start inets for you :-P

If you are keen on not using applications, I guess the choice depends on how your code works. If you will always need inets to be started, it is better started by any of your supervisors. If it is rarely needed, you can always make sure it is started with something like:

ensure_app_started(App) ->
  case application:started(App) of
    ok -> ok;
    {error, already_started} -> ok;
    Error -> Error
  end.

Tags:

Erlang

Inets