Last active
December 29, 2015 12:49
-
-
Save robbielynch/7673030 to your computer and use it in GitHub Desktop.
Erlang - Ping Pong
Example of message sending in erlang.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%% @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