22 lines
504 B
Elixir
22 lines
504 B
Elixir
defmodule Broker do
|
|
use GenServer
|
|
|
|
def start_link({:tcp, port, to_host, to_port}) do
|
|
GenServer.start_link(__MODULE__, {:tcp, port, to_host, to_port})
|
|
end
|
|
|
|
@impl true
|
|
def init({:tcp, port, to_host, to_port}) do
|
|
{:ok, listen_socket} =
|
|
:gen_tcp.listen(port, [
|
|
:binary,
|
|
reuseaddr: true,
|
|
active: true,
|
|
backlog: 100
|
|
])
|
|
|
|
TcpWatcher.start_link({to_host, to_port, listen_socket})
|
|
{:ok, {:tcp, port, to_host, to_port, listen_socket}}
|
|
end
|
|
end
|