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

David Cabana <>
Wed Oct 29 19:44:24 CET 2008


I've now played with both of  Ulf's suggested approaches  (using
io:format(user, Fmt, Args), or alternatively, resetting processes group
leaders) and have gotten output to go the correct consoles with both
approaches.  Which of course led to the next hurdle,  reading input from the
player console.

The referee sent a question to the player, which was written to the player
node's console. What I want to do is type a response in the player console,
have it read, parsed, and sent to the referee, but so far no luck. My
responses vanish into the ether, and the referee hangs waiting for players
to respond.

Here is how I am trying to respond. When the player process receives a
question, it writes to the console and tries to read a line:

<when I have reset player group leaders>
    io:fwrite("~n~s", [Question]),
    Reply = io:get_line(["= "]),

<did not mess with group leaders, instead specified the 'user' atom during
io>
I have also tried:
    io:fwrite(user, "~n~s", [Question]),
    Reply = io:get_line(user, ["= "]),


It occurs to me that maybe I am going about this the wrong way? Perhaps my
approch is misconceived.  I have to believe that console IO in a
client-server setting is pretty common. Can anyone point me in the right
direction?

Thank you,
David

>
> On Fri, Oct 24, 2008 at 2:44 PM, Ulf Wiger (TN/EAB) <
> > wrote:
>
>> David Cabana skrev:
>> >
>>
>>> 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?
>>>
>>
>> Use io:format(user, Fmt, Args)
>>
>> Alternatively, set the group leader of the process to some
>> local process - e.g. the group leader of net_kernel
>> (found by calling process_info(whereis(net_kernel),group_leader)).
>>
>> The group leader is the process that's handed all io messages.
>> The rpc server deliberately sets the group leader of an rpc
>> handler process to that of the caller on the originating node,
>> since the remote node may not always have a tty to print to.
>> When spawning, the group leader of the spawned process will
>> be inherited from the parent. If you spawn a process on
>> another node, it will still have the same group leader as
>> the parent.
>>
>> The BIF group_leader(Pid,New_group_leader_pid) sets a new
>> leader.
>>
>> BR,
>> Ulf W
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081029/b904a731/attachment.html>


More information about the erlang-questions mailing list