20 lines
396 B
Elixir
20 lines
396 B
Elixir
defmodule Broadcast.ClientHandler do
|
|
use Task
|
|
|
|
def start(sock) do
|
|
Task.start_link(__MODULE__, :handle, [sock])
|
|
end
|
|
|
|
def handle(sock) do
|
|
case :gen_tcp.recv(sock, 0) do
|
|
{:ok, line} ->
|
|
Broadcast.Server.broadcast("Someone said: " <> line)
|
|
handle(sock)
|
|
|
|
{:error, _} ->
|
|
:gen_tcp.close(sock)
|
|
Broadcast.Server.remove_client()
|
|
end
|
|
end
|
|
end
|