- Notifications
You must be signed in to change notification settings - Fork2
Evews - Erlang Lightweigth Websocket RFC 6455
License
zgbjgg/evews
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
evews - Lightweight Websocket RFC 6455 - v1.9
Clone the evews repo:
$ git clone https://github.com/jorgegarrido/evews.git
To compile you will need 'rebar', with debug logging enabled:
$ make debug=on compile
Or without debug (option for not create a long messages in the logs)
$ make compile
To start the evews websocket server just add the ebin/ path, process that controls the sokcte is designed as anon-blocking socket (tcp/ssl) to accept many concurrents connections at the same time, to start supervisor, itneeds the next args:
* Port - the port where websocket runs* Ws Handler - the module and function that manages the websocket (as a callback module), here you can receive & send messages* Ssl - Certfile, Keyfile and password (if any)
this is a simple example how to start evews websocket server on port 8081 and the callback module example:loop/1 :
evews_sup:start_link([{port,8081}, {ws_handler, [{callback_m,example}, {callback_f,loop}]}]).
the callback module 'example' must have a function named loop which receives one parameter, a tuple with the websocketmodule and the record with the info about it, and this function is a simple process that receives messages from the broswer with the tuple '{browser, Data}', callback module function looks like this:
loop({Ws,WsInfo})->receive {browser,Data} ->io:format("receive~p\n", [Ws:get(Data)]),loop({Ws,WsInfo});Any ->io:format("any~p\n", [Any]),loop(Ws)after1000 ->Ws:send(["echo!"]),loop({Ws,WsInfo})end.
check theevews_example.erl module for more info
NOTE Evews is no longer managed by a parametrized module.
Evews Websocket can retrieve info about connection, WsInfo is present on your callback module and is used on each function, the next are the options in Ws:
Ws:get(Data)Gets the messageWs:send(Msg, WsInfo)Sends the message to the browser, Msg can be a string or iolistWs:socket(WsInfo)Returns the port for this socketWs:peername(WsInfo)Returns the address and port for the other end of a connectionWs:port(WsInfo)Returns the local port number of this socketWs:sockname(WsInfo)Returns the local address and port number of this socket.
THIS SOFTWARE IS LICENSED UNDER BSD LICENSE. see LICENSE.txt for more info