README.md 2.6 KB

N4U (N2O FOR YOU): Erlang Application Server

Dependencies

do not forget

sudo apt-get install esl-erlang
# or install erlang with kerl

sudo apt-get install git
sudo apt-get install gcc
sudo apt-get install make
sudo apt-get install build-essential
sudo apt-get install inotify-tools

Features

  • Formatters: BERT, JSON — changeable on the fly
  • Protocols: N2O, NITRO, SPA, FTP
  • Endpoints: WebSocket, HTTP, REST
  • High Performance Protocol Relay
  • Smallest possible codebase — 1K LOC
  • BEAM/LING support on posix, arm, mips and xen platforms
  • Single-file atomic packaging with MAD
  • Handlers
    • PubSub: MQS, GPROC, SYN
    • Templates: DTL, NITRO
    • Sessions: server driven
    • DOM Language: SHEN JavaScript Compiler
    • Error Logging: IO, LOGGER
    • Security: PLAIN, AES CBC 128
  • Speed: 30K conn/s at notebook easily
  • Samples: Skyline (DSL), Games (SPA), Review (KVS), Sample (MAD)

Message Formatters

You can use any message formmatter at the bottom of N2O protocol. IO messages supported by the N2O protocol are as follows:

1. BERT : {io,"console.log('hello')",1}
2. WAMP : [io,"console.log('hello')",1]
3. JSON : {name:io,eval:"console.log('hello')",data:1}
4. TEXT : IO console.log('hello') 1\n
5. XML  : <io><eval>console.log('hello')</eval><data>1</data></io>

Besides, you can even switch a channel termination formatter on the fly within one WebSocket session.

All Features in One snippet

-module(index).
-compile([export_all, nowarn_export_all]).
-include_lib("nitro/include/nitro.hrl").
-include_lib("n4u/include/n4u.hrl").

peer()    -> io_lib:format("~p",[wf:peer(?REQ)]).
message() -> wf:js_escape(wf:html_encode(wf:q(message))).
main()    -> #dtl{file="index",app=n4u_sample,bindings=[{body,body()}]}.
body() ->
    {Pid,_} = wf:async(fun(X) -> chat_loop(X) end),
    [ #panel{id=history}, #textbox{id=message},
      #button{id=send,body="Chat",postback={chat,Pid},source=[message]} ].

event(init) -> wf:reg(room);
event({chat,Pid}) -> Pid ! {peer(), message()};
event(Event) -> skip.

chat_loop({Peer, Message} ) ->
       wf:insert_bottom(history,#panel{body=[Peer,": ",Message,#br{}]}),
       wf:flush(room) end.

Documentation

  • Official N2O v4.4 Book (outdated) PDF

OM A HUM