fixup
This commit is contained in:
26
lib/broker.ex
Normal file
26
lib/broker.ex
Normal file
@@ -0,0 +1,26 @@
|
||||
defmodule Broker do
|
||||
use GenServer
|
||||
|
||||
def init(opts) do
|
||||
{:ok, listen_socket} =
|
||||
:gen_tcp.listen(opts[:port], [
|
||||
:binary,
|
||||
reuseaddr: true,
|
||||
active: false,
|
||||
backlog: 100
|
||||
])
|
||||
|
||||
{:ok, opts}
|
||||
end
|
||||
|
||||
defp accept_loop(listen_socket) do
|
||||
case :gen_tcp.accept(listen_socket) do
|
||||
{:ok, socket} ->
|
||||
spawn(__MODULE__, :handle_client, [socket])
|
||||
accept_loop(listen_socket)
|
||||
|
||||
{:error, reason} ->
|
||||
IO.puts("接受連接失敗: #{reason}")
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user