elixir-broadcast/lib/client.ex
Emin Arslan 1503ca4fab Initial
2025-02-16 19:14:35 +03:00

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