I'm trying to execute a very simple Erlang code, and it's not working. I've tryied executed some hello worlds without problem, but not mine own code.
-module(server).
%% Exported Functions
-export([start/0, process_requests/1]).
%% API Functions
start() ->
ServerPid = spawn(server, process_requests, [[]]),
register(myserver, ServerPid).
process_requests(Clients) ->
receive
{client_join_req, Name, From} ->
NewClients = [From|Clients], %% TODO: COMPLETE
broadcast(NewClients, {join, Name}),
process_requests(NewClients); %% TODO: COMPLETE
{client_leave_req, Name, From} ->
NewClients = lists:delete(From, Clients), %% TODO: COMPLETE
broadcast(Clients, {leave, Name}), %% TODO: COMPLETE
process_requests(NewClients); %% TODO: COMPLETE
{send, Name, Text} ->
broadcast(Clients, {message, Name, Text}), %% TODO: COMPLETE
process_requests(Clients)
end.
%% Local Functions
broadcast(PeerList, Message) ->
Fun = fun(Peer) -> Peer ! Message end,
lists:map(Fun, PeerList).
Compile result:
5> c(server).
{ok,server}
6> server:start().
** exception error: undefined function server:start/0