<commit_before>Listeners
=========

Purpose
-------

A listener is a set of processes whose role is to listen on a port
for new connections. It manages a pool of acceptor processes, each
of them indefinitely accepting connections. When it does, it starts
a new process executing the protocol handler code. All the socket
programming is abstracted through the user of transport handlers.

The listener takes care of supervising all the acceptor and connection
processes, allowing developers to focus on building their application.

Starting and stopping
---------------------

Ranch does nothing by default. It is up to the application developer
to request that Ranch listens for connections.

A listener can be started and stopped at will.

When starting a listener, a number of different settings are required:
 *  A name to identify it locally and be able to interact with it.
 *  The number of acceptors in the pool.
 *  A transport handler and its associated options.
 *  A protocol handler and its associated options.

Ranch includes both TCP and SSL transport handlers, respectively
`ranch_tcp` and `ranch_ssl`.

A listener can be started by calling the `ranch:start_listener/6`
function. Before doing so however, you must ensure that the `ranch`
application is started.

To start the `ranch` application:

``` erlang
ok = application:start(ranch).
```

You are then ready to start a listener. Let's call it `tcp_echo`. It will
have a pool of 100 acceptors, use a TCP transport and forward connections
to the `echo_protocol` handler.

``` erlang
{ok, _} = ranch:start_listener(tcp_echo, 100,
    ranch_tcp, [{port, 5555}],
    echo_protocol, []
).
```

You can try this out by compiling and running the `tcp_echo` example in the
examples directory. To do so, open a shell in the `examples/tcp_echo/`
directory and run the following commands:

```
% rebar get-deps compile
% ./start.sh
Listening on port 5555
```

You can then connect to it using telnet and see the echo server reply
everything you send to it. Then when you're done testing, you can use
the `Ctrl+]` key to escape to the telnet command line and type
`quit` to exit.

```
% telnet localhost 5555
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Hello!
Hello!
It works!
It works!
^]

telnet> quit
Connection closed.
```

Default transport options
-------------------------
<commit_msg>Fix an example in the guide<commit_after>Listeners
=========

Purpose
-------

A listener is a set of processes whose role is to listen on a port
for new connections. It manages a pool of acceptor processes, each
of them indefinitely accepting connections. When it does, it starts
a new process executing the protocol handler code. All the socket
programming is abstracted through the user of transport handlers.

The listener takes care of supervising all the acceptor and connection
processes, allowing developers to focus on building their application.

Starting and stopping
---------------------

Ranch does nothing by default. It is up to the application developer
to request that Ranch listens for connections.

A listener can be started and stopped at will.

When starting a listener, a number of different settings are required:
 *  A name to identify it locally and be able to interact with it.
 *  The number of acceptors in the pool.
 *  A transport handler and its associated options.
 *  A protocol handler and its associated options.

Ranch includes both TCP and SSL transport handlers, respectively
`ranch_tcp` and `ranch_ssl`.

A listener can be started by calling the `ranch:start_listener/6`
function. Before doing so however, you must ensure that the `ranch`
application is started.

To start the `ranch` application:

``` erlang
ok = application:start(ranch).
```

You are then ready to start a listener. Let's call it `tcp_echo`. It will
have a pool of 100 acceptors, use a TCP transport and forward connections
to the `echo_protocol` handler.

``` erlang
{ok, _} = ranch:start_listener(tcp_echo, 100,
    ranch_tcp, [{port, 5555}],
    echo_protocol, []
).
```

You can try this out by compiling and running the `tcp_echo` example in the
examples directory. To do so, open a shell in the `examples/tcp_echo/`
directory and run the following commands:

``` bash
% rebar get-deps compile
% ./start.sh
Listening on port 5555
```

You can then connect to it using telnet and see the echo server reply
everything you send to it. Then when you're done testing, you can use
the `Ctrl+]` key to escape to the telnet command line and type
`quit` to exit.

```
% telnet localhost 5555
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Hello!
Hello!
It works!
It works!
^]

telnet> quit
Connection closed.
```

Default transport options
-------------------------

{'fraction_non_alphanumeric': 0.08719346049046321, 'fraction_numerical': 0.010479983232026828, 'mean_word_length': 3.7959798994974876, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6372882', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1260, 'n_words': 688}