Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Evews - Erlang Lightweigth Websocket RFC 6455

License

NotificationsYou must be signed in to change notification settings

zgbjgg/evews

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

evews - Lightweight Websocket RFC 6455 - v1.9

Hex.pmLicenseHex.pmHex.pm

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 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

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

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp