SAMPLE

INTRO

SAMPLE is a regular Erlang application.

HEADER

Picture 1. HOW TO SETUP BOTH APP AND SUP IN ERLANG
-module(sample). -behaviour(supervisor). -behaviour(application). -export([init/1, start/0, start/2, stop/1, main/1]).

OTP

Note that suring start you should specify mauth module. Dafault implementation performs client topic autosubscription.

Picture 2. Implements Erlang/OTP service API
start() -> start(normal,[]). start(_,_) -> supervisor:start_link({local,SAMPLE},SAMPLE,[]). stop(_) -> ok.

COWBOY

SAMPLE application uses COWBOY as a static HTTP server and as a WebSocket server.

Picture 3. COWBOY setup
start(_,_) -> cowboy:start_tls(http,n2o_cowboy:env(?MODULE), #{env=>#{dispatch=>n2o_cowboy2:points() }}), supervisor:start_link({local,sample},sample,[]).