Skip to content

Instantly share code, notes, and snippets.

@robbielynch
Last active December 29, 2015 12:49
Show Gist options
  • Save robbielynch/7673030 to your computer and use it in GitHub Desktop.
Save robbielynch/7673030 to your computer and use it in GitHub Desktop.
Erlang - Ping Pong Example of message sending in erlang.
%%% @author Robbie <[email protected]>
%%% @copyright (C) 2013, Robbie
%%% @doc
%%% Program to test message passing between two processes
%%% @end
%%% Created : 8 Nov 2013 by Robbie <[email protected]>
-module(pingpong).
-export([start/0, ping/0, pong/0]).
start()->
PingPid = spawn(pingpong, ping, []),
PongPid = spawn(pingpong, pong, []),
PingPid!{PongPid, pong}.
ping()->
receive
{PongPid, pong}-> io:format("pong recieved~n"),
PongPid!{self(), ping}
end,
ping().
pong()->
receive
{Pid, ping}-> io:format("ping recieved~n"),
Pid!{self(), pong}
end,
pong().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment