% chat_acceptor.erl % Copyright 2005 Michael Leonhard % All Rights Reserved. % http://tamale.net/ -module(chat_acceptor). -export([acceptor_start/0]). acceptor_start() -> io:fwrite("acceptor ~w: starting~n", [self()]), Port = 5679, {ok, LSock} = gen_tcp:listen(Port, [binary, {packet, line}, {active, false}, {reuseaddr, true}]), io:fwrite("acceptor: listening on port ~B~n", [Port]), acceptor_loop(LSock). acceptor_loop(LSock) -> case gen_tcp:accept(LSock) of {ok, Socket} -> io:fwrite("acceptor: accepted connection ~w~n", [Socket]), PID = spawn(chat_liason, liason_start, []), chat_liason:deliver_socket(Socket, PID), acceptor_loop(LSock); {error, Reason} -> io:fwrite("acceptor: stopping because of ~w~n", Reason), exit(Reason) end.