Skip to content

Instantly share code, notes, and snippets.

@zeisss
Created August 31, 2013 10:35
Show Gist options
  • Save zeisss/6397433 to your computer and use it in GitHub Desktop.
Save zeisss/6397433 to your computer and use it in GitHub Desktop.
-module(echo_server).
-compile(export_all).
%%% === Public API
start_link() ->
spawn_link(fun() -> ok = init(), loop() end).
echo(Node, Message) ->
echo(Node, Message, 5000).
echo(Node, Message, Timeout) ->
{?MODULE, Node} ! {'echo$', self(), Message},
receive
{'echo$response', Message} ->
ok
after Timeout ->
timeout
end.
%%% === Internal API
init() ->
register(?MODULE, self()),
ok.
loop() ->
receive
{'echo$', From, Message} ->
From ! {'echo$response', Message},
loop();
'echo$exit' ->
ok
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment