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

后端 未结 3 1592
小鲜肉
小鲜肉 2021-01-18 10:03

What is the appropriate place for performing inets:start() ?

  1. in `applicationname_app\' module?
  2. in applicationname_sup superv
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-18 10:40

    If your code is packaged as an application, list inets in the application resource file:

    % Filename: ebin/flamingo.app
    {application, flamingo,
      [{vsn, "1.0.0"},
       {modules, [flamingo_app,
                  flamingo_sup,
                  flamingo]},
       {applications, [kernel,
                       stdlib,
                       inets]},
       {mod, {flamingo_app, []}}
      ]}.
    

    Then you can start the application using application:ensure_all_started(flamingo). This ensures that inets is started automatically for you (i.e. there is no need to explicitly call inets:start()).

    For example (assuming the *.app file and *.beam files and are in ebin/):

    $ erl -pa ebin/
    Eshell V9.2  (abort with ^G)
    1> application:ensure_all_started(flamingo).
    {ok,[inets,flamingo]}
    

提交回复
热议问题