# `HL7v2.MLLP.Listener`
[🔗](https://github.com/Balneario-de-Cofrentes/hl7v2/blob/v3.10.1/lib/hl7v2/mllp/listener.ex#L1)

MLLP TCP listener using Ranch 2.x.

Starts a TCP (or TLS) listener that accepts MLLP connections and dispatches
messages to the configured handler module.

## Options

- `:port` (required) — TCP port to listen on. Use `0` for OS-assigned port.
- `:handler` (required) — module implementing `HL7v2.MLLP.Handler`.
- `:handler_state` — arbitrary term passed to the handler in metadata.
- `:ref` — Ranch listener reference (default: auto-generated atom).
- `:num_acceptors` — number of acceptor processes (default: `10`).
- `:tls` — keyword list of TLS options. When present, Ranch uses `:ranch_ssl`
  instead of `:ranch_tcp`. See `HL7v2.MLLP.TLS` for helpers.
- `:timeout` — idle connection timeout in milliseconds (default: `60_000`).
- `:max_message_size` — maximum MLLP message buffer size in bytes per
  connection (default: `10_485_760` — 10 MB). Connections exceeding this
  limit are closed.
- `:handler_timeout` — maximum time in milliseconds for the handler to
  process a single message (default: `60_000`). If exceeded, the handler
  process is killed and the connection continues.

## Examples

    {:ok, pid} = HL7v2.MLLP.Listener.start_link(
      port: 2575,
      handler: MyHandler
    )

    # Get the assigned port (useful when port: 0)
    port = HL7v2.MLLP.Listener.port(pid)

    # Stop the listener
    HL7v2.MLLP.Listener.stop(pid)

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `port`

```elixir
@spec port(GenServer.server()) :: :inet.port_number()
```

Returns the port the listener is bound to.

Useful when the listener was started with `port: 0` for OS-assigned ports.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Starts an MLLP listener.

See module documentation for available options.

# `stop`

```elixir
@spec stop(GenServer.server()) :: :ok
```

Stops an MLLP listener.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
