This commit is contained in:
Emin Arslan
2025-02-16 19:14:35 +03:00
commit 1503ca4fab
9 changed files with 194 additions and 0 deletions

19
lib/client.ex Normal file
View File

@@ -0,0 +1,19 @@
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