Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zgbjgg/evews
Evews - Erlang Lightweigth Websocket RFC 6455
https://github.com/zgbjgg/evews
erlang lightweight rfc-6455 websocket
Last synced: about 1 month ago
JSON representation
Evews - Erlang Lightweigth Websocket RFC 6455
- Host: GitHub
- URL: https://github.com/zgbjgg/evews
- Owner: zgbjgg
- License: bsd-3-clause
- Created: 2013-04-05T20:08:56.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2019-11-27T17:19:29.000Z (almost 5 years ago)
- Last Synced: 2024-09-30T03:42:15.460Z (about 2 months ago)
- Topics: erlang, lightweight, rfc-6455, websocket
- Language: Erlang
- Homepage: https://github.com/zgbjgg/evews
- Size: 1.03 MB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
evews
=====evews - Lightweight Websocket RFC 6455 - v1.9
[![Hex.pm](https://img.shields.io/hexpm/v/evews.svg)](https://hex.pm/packages/evews)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![Hex.pm](https://img.shields.io/hexpm/dt/evews.svg)](https://hex.pm/packages/evews)
[![Hex.pm](https://img.shields.io/hexpm/dw/evews.svg)](https://hex.pm/packages/evews)download & build
====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
start
====To start the evews websocket server just add the ebin/ path, process that controls the sokcte is designed as a
non-blocking socket (tcp/ssl) to accept many concurrents connections at the same time, to start supervisor, it
needs 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 :```erlang
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 websocket
module 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:```erlang
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)
after 1000 ->
Ws:send(["echo!"]),
loop({Ws, WsInfo})
end.
```check the [evews_example.erl](https://github.com/jorgegarrido/evews/blob/master/examples/evews_example.erl) module for more info
exports
======> 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.
LICENSE
======THIS SOFTWARE IS LICENSED UNDER BSD LICENSE. see LICENSE.txt for more info