N2O

Endpoints

Here is a list of types of endpoints which are supported by EMQ and accessible to N2O apps: WebSockets, MQTT, MQTT-SN, TCP, UDP, CoAP. Normal use of N2O as a Web Framework or a Web Application Server is through WebSockets, but for IoT and MQTT applications it could be served through UDP or SCTP protocols, providing application level message delivery consistency. By using MQTT as a transport we extend the supported set of endpoint protocols.

MQTT

EMQ is an open-source MQTT broker implemented by Feng Lee. N2O is EMQ compatible plugin that acts as predefined MQTT clients that form a ring of virtual nodes, process all the protocol requests, and answer to client topics according to classical RPC over MQ schema. This list of modules forms a core of N2O that is common for both MQTT and WebSocket versions:

  • n2o — N2O Application
    : MQTT and WS — 10KB
  • n2o_pi — N2O Processes
    — 4KB
  • n2o_proto — N2O Loop
    : — 1KB
  • n2o_ring — N2O Ring
    : Hash Ring — 1KB
$ mad app zero review $ cd review $ mad dep com pla rep $ open http://127.0.0.1:8000

The list of MQTT specific modules:

  • n2o_auth — N2O MQTT Authentication
    : MQTT auth module — 1KB
  • n2o_mqtt — MQTT DHT Processing Node

WebSocket

COWBOY is small, fast, and modern HTTP server implemented by Loïc Hoguin. In this version, N2O loop is integrated as WebSocket cowboy handler that routes all incoming messages to N2O. The list of WebSocket specific modules:

$ mad app nitro sample $ cd sample $ mad dep com pla rep $ open https://127.0.0.1:8001/app/index.htm

Protocols

  • n2o_heart — PING protocol
  • n2o_ftp — N2O File Protocol
    : FTP — 4KB
  • n2o_nitro — N2O Nitrogen Web Framework Protocol
    : — 3KB

Services

JavaScript

SPEC

N2O:
-type n2o() :: #bert{} | #json{} | #binary{} | #default{}. -type cx() :: #cx{}. -type formatter() :: binary | json | bert | text | default | atom(). -type response() :: { formatter(), binary() }. -record(ok, { data :: term() }). -record(error { data :: term() }. -record(reply, { msg :: n2o(), req :: term(), ctx :: cx() } ). -record(unknown, { msg :: n2o(), req :: term(), ctx :: cx() } ). -spec start(#pi{}) -> {pid(),term()} | #error{}. -spec stop(term(),atom()) -> #pi{} | #error{}. -spec proc(atom(),#pi{}) -> term(). -spec info(term(),term(),#cx{}) -> #reply{} | #unknown{}. -record(pi, { name :: term(), table :: atom(), sup :: atom(), module :: atom(), state :: term() }). -record(cx, { handlers = [] :: list({atom(),atom()}), actions = [] :: list(tuple()), req = [] :: [] | term(), module = [] :: [] | atom(), lang = [] :: [] | atom(), path = [] :: [] | binary(), session = [] :: [] | binary(), formatter = bert :: bert | json | atom(), params = [] :: [] | list(tuple()), node = [] :: [] | atom(), client_pid = [] :: [] | term(), state = [] :: [] | term(), from = [] :: [] | binary(), vsn = [] :: [] | binary() }). -type memtable() :: atom(). -spec encode(tuple()) -> binary(). -spec decode(binary()) -> tuple(). -spec session(term(),term()) -> term(). -spec session(term()) -> term(). -spec cache(memtable(),term(),term()) -> term(). -spec cache(memtable(),term()) -> term().