Exercise 4-1: An Echo Server

347 views
Skip to first unread message

pugsley

unread,
Feb 10, 2010, 11:39:00 PM2/10/10
to Erlang Programming
Hi,

Here's my solution for Exercise 4-1: An Echo Server.

%% Erlang Programming
%% Exercise 4-1: An Echo Server
-module(echo).
-export([start/0,print/1,stop/0]).
-export([loop/0]).

start() ->
register(echo, spawn(echo, loop, [])),
ok.

print(Msg) ->
echo ! {print, Msg},
ok.

stop() ->
echo ! stop,
ok.


loop() ->
receive
{print, Msg} ->
io:format("~w~n", [Msg]),
loop();
stop ->
true
end.

Nataly

unread,
Nov 27, 2012, 7:37:36 AM11/27/12
to erlang-prog...@googlegroups.com
An error occurs during the execution this code.

=ERROR REPORT==== 27-Nov-2012::16:23:39 ===
Error in process <0.44.0> with exit value: {undef,[{echo,loop,[],[]}]}

I don't understand why. Could you please help me.

Simon Thompson

unread,
Nov 27, 2012, 11:13:06 AM11/27/12
to erlang-prog...@googlegroups.com
This may well be because you didn't export the loop function from the echo module.

Simon


--
Erlang Programming Website:
http://www.erlangprogramming.org/

Simon Thompson | Professor of Logic and Computation 
School of Computing | University of Kent | Canterbury, CT2 7NF, UK
s.j.th...@kent.ac.uk | M +44 7986 085754 | W www.cs.kent.ac.uk/~sjt


Nataly

unread,
Nov 27, 2012, 11:17:10 PM11/27/12
to erlang-prog...@googlegroups.com
Thank you for your answer. I found an error. I renamed the module -module(echo3), but forgot to change the string register(echo, spawn(echo, loop, [])).

вторник, 27 ноября 2012 г., 20:13:04 UTC+4 пользователь Simon Thompson написал:
Reply all
Reply to author
Forward
0 new messages