aboutsummaryrefslogtreecommitdiff
path: root/step-05/echo_server.erl
diff options
context:
space:
mode:
Diffstat (limited to 'step-05/echo_server.erl')
-rw-r--r--step-05/echo_server.erl22
1 files changed, 22 insertions, 0 deletions
diff --git a/step-05/echo_server.erl b/step-05/echo_server.erl
new file mode 100644
index 0000000..3f531e5
--- /dev/null
+++ b/step-05/echo_server.erl
@@ -0,0 +1,22 @@
+-module(echo_server).
+
+-export([start/0, loop/1]).
+
+loop(0) ->
+ io:format("ping finished~n", []);
+
+loop(N) ->
+ receive
+ {ping, Node} ->
+ io:format("~w: Got ping req from: ~w~n", [self(), Node]),
+ Node ! {pong, self()};
+ X ->
+ io:format("Unexpected message: ~w~n", [X])
+ end,
+ echo_server:loop(N - 1).
+
+start() ->
+ Pid = spawn(echo_server, loop, [10]),
+ io:format("Starting server, pid=~w~n", [Pid]),
+ io:format("Starting server, pid=~w~n", [Pid]),
+ register(echo, Pid).