[erlang-questions] Question re console io in a distributed computation

David Cabana <>
Fri Oct 24 19:18:18 CEST 2008


I'm writing a simple distributed quiz game intended to work as follows.

A referee process waits for two player processes to join the game.
Once the players have joined, the referee sends the players questions, and
the players
respond with answers. The first player to correctly answer N questions is
the winner.

My initial approach was to get dummy messages flowing on a single erlang
node.
To see that this is working, I write to the console upon receipt of
messages, as
seen below, in the main loop of a player process.

loop(Nickname)->
    receive
        {_From, stop} ->
            io:format("~p:: ~p received stop msg ~n", [?MODULE, Nickname]),
            player_stopped;

        {From, {question, N} } ->
            io:format("~p:: ~p received question ~p~n", [?MODULE, Nickname,
N]),
            From ! {self(), {answer,N} },
            loop(Nickname);

        Other ->
            io:format("~p ~p received unknown msg ~p~n", [?MODULE, Nickname,
Other]),
            loop(Nickname)
    end.

Everything worked as expected on a single node, so my next step was to get
things working
across multiple nodes.  I created a referee node and two player nodes, each
running its
respective process.  The messages flow correctly, but all the terminal io
happens in
a single console, the one associated with the referee node.

My question is how to get player output written to the console of the
corresponding
player node? Eventually I want the nodes to run on separate computers, and
the
console output (questions) to be read by actual players, so I need the
output to go to
the right place.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081024/3489a268/attachment.html>


More information about the erlang-questions mailing list