<commit_before>Erwa
====
[![passing or failing?](https://travis-ci.org/bwegh/erwa.svg?branch=master)](https://travis-ci.org/bwegh/erwa/)


Erwa is an implementation of [WAMP (Web Application Messaging Protocol)](http://wamp.ws/spec/) in Erlang,
both peer and router.



Table of Contents
=================

* [Description](#description)
* [Router](#router)
* [Peer](#peer)
* [Examples](#examples)
* [License](#license)


Description
===========
Erwa is the implementation of the WAMP protocol in Erlang.
It supports the router and the peer role, so the client and
the server side.

The project is still in early development, so I am happy to get any
kind of feedback.

[Back to TOC](#table-of-contents)


Router
======
The router implementation in Erwa uses the great [ranch](https://github.com/extend/ranch)
and [cowboy](https://github.com/extend/cowboy) from [<NAME> (essen)](https://github.com/essen)
to handle the incomming connections and the webserver part for the websockets.
Erwa has two modules to work either as a protocol for ranch on incomming TCP connections, or
as websocket handler with cowboy on incomming websocket connections.

The features of the router are:
* the basic profile
* both router roles
  * Dealer
  * Broker

All you need to do to get a simple WAMP router up and running is to add a dispatch rule to
ranch and/or cowboy:

A WAMP router on websockets:
* using erwa_ws_handler as the websocket handler, by dispatching a certain path to conditions
* starting cowboy on a certain port (here 8080) and add the dispatch rule
```Erlang
%% a rule to dispatch incomming connections to any host with the path /wamp to the erwa_ws_handler
Dispatch = cowboy_router:compile([ {'_', [ {"/wamp", erwa_ws_handler, []}, ]} ]),
%% fire up cowboy with the dispatch rule for the wamp connection
{ok, _} = cowboy:start_http(http, 100, [{port, 8080}],[{env, [{dispatch, Dispatch}]}]),
```
In the examples directory you can find the simple_router which includes just the above
and starts a WAMP router, including a simple javascript client,
using [wampy.js](https://github.com/KSDaemon/wampy.js).

The other possibility is to start Erwa as a TCP router:
Erwa implements a protocol for ranch in the erwa_tcp_handler modules.
So starting and tcp router is done by starting ranch with
erwa_tcp_handler as the protocol:
```Erlang
%% start ranch with the wamp protocol by using erwa_tcp_handler on port 555
{ok,_} = ranch:start_listener(erwa_tcp, 5, ranch_tcp, [{port,5555}], erwa_tcp_handler, []),
```
This is also included in the simple_router example in the examples directory.

By default Erwa does not automatically create realms. This is activated by the boolean
*autocreate_realm* flag.
If you only want to support certain realm you need to start them by using erwa:start_realm/1,
which takes the name of the realm to start as argument.

[Back to TOC](#table-of-contents)


Peer
====
Erwa implements the basic profile for all four roles of a peer, caller and callee as well as
publisher and subscriber.
The connection to the router can either be remote to another host/port or local to a router
running within the same VM.

The connections are implemented as gen_server and can be shared between different processes.
The Idea is to have just one connection to a router and share it with all needing processes.
*A lookup of connections to certain routers and realms is not yet implemented, yet under consideration*

To connect to a realm you need to follow a few simple steps:
```Erlang
%% first start a connection
{ok,Con} = erwa:start_client(),
%% then connect to either a local or remote router
%% local would be
{ok,SessionId,RouterDetails} = erwa:connect(Con,Realm),
%% the following is a remote router
{ok,SessionId,RouterDetails} = erwa:connect(Con,Host,Port,Realm,Encoding),<commit_msg>Fix documentation regarding erwa_in_handler<commit_after>Erwa
====
[![passing or failing?](https://travis-ci.org/bwegh/erwa.svg?branch=master)](https://travis-ci.org/bwegh/erwa/)


Erwa is an implementation of [WAMP (Web Application Messaging Protocol)](http://wamp.ws/spec/) in Erlang,
both peer and router.



Table of Contents
=================

* [Description](#description)
* [Router](#router)
* [Peer](#peer)
* [Examples](#examples)
* [License](#license)


Description
===========
Erwa is the implementation of the WAMP protocol in Erlang.
It supports the router and the peer role, so the client and
the server side.

The project is still in early development, so I am happy to get any
kind of feedback.

[Back to TOC](#table-of-contents)


Router
======
The router implementation in Erwa uses the great [ranch](https://github.com/extend/ranch)
and [cowboy](https://github.com/extend/cowboy) from [<NAME> (essen)](https://github.com/essen)
to handle the incomming connections and the webserver part for the websockets.
Erwa has two modules to work either as a protocol for ranch on incomming TCP connections, or
as websocket handler with cowboy on incomming websocket connections.

The features of the router are:
* the basic profile
* both router roles
  * Dealer
  * Broker

All you need to do to get a simple WAMP router up and running is to add a dispatch rule to
ranch and/or cowboy:

A WAMP router on websockets:
* using erwa_in_handler as the websocket handler, by dispatching a certain path to conditions
* starting cowboy on a certain port (here 8080) and add the dispatch rule
```Erlang
%% a rule to dispatch incomming connections to any host with the path /wamp to the erwa_in_handler
Dispatch = cowboy_router:compile([ {'_', [ {"/wamp", erwa_in_handler, []}, ]} ]),
%% fire up cowboy with the dispatch rule for the wamp connection
{ok, _} = cowboy:start_http(http, 100, [{port, 8080}],[{env, [{dispatch, Dispatch}]}]),
```
In the examples directory you can find the simple_router which includes just the above
and starts a WAMP router, including a simple javascript client,
using [wampy.js](https://github.com/KSDaemon/wampy.js).

The other possibility is to start Erwa as a TCP router:
Erwa implements a protocol for ranch in the erwa_in_handler modules.
So starting and tcp router is done by starting ranch with
erwa_in_handler as the protocol:
```Erlang
%% start ranch with the wamp protocol by using erwa_in_handler on port 555
{ok,_} = ranch:start_listener(erwa_tcp, 5, ranch_tcp, [{port,5555}], erwa_in_handler, []),
```
This is also included in the simple_router example in the examples directory.

By default Erwa does not automatically create realms. This is activated by the boolean
*autocreate_realm* flag.
If you only want to support certain realm you need to start them by using erwa:start_realm/1,
which takes the name of the realm to start as argument.

[Back to TOC](#table-of-contents)


Peer
====
Erwa implements the basic profile for all four roles of a peer, caller and callee as well as
publisher and subscriber.
The connection to the router can either be remote to another host/port or local to a router
running within the same VM.

The connections are implemented as gen_server and can be shared between different processes.
The Idea is to have just one connection to a router and share it with all needing processes.
*A lookup of connections to certain routers and realms is not yet implemented, yet under consideration*

To connect to a realm you need to follow a few simple steps:
```Erlang
%% first start a connection
{ok,Con} = erwa:start_client(),
%% then connect to either a local or remote router
%% local would be
{ok,SessionId,RouterDetails} = erwa:connect(Con,Realm),
%% the following is a remote router
{ok,SessionId,RouterDetails} = erwa:connect(Con,Host,Port,Realm,Encoding),
{'fraction_non_alphanumeric': 0.09248100602567462, 'fraction_numerical': 0.0052397170552790145, 'mean_word_length': 4.9929356357927785, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6356005', 'n_tokens_mistral': 2253, 'n_tokens_neox': 2164, 'n_words': 1016}