question about 'irc lite'
Ittay Dror
2 posts
|
Hi, I’m reading the book and I enjoy it very much. Good book, excellent language! However, I have a problem understanding the chat server example on chapter 11. In the code I see that when a string is typed into Widget it is sent with ‘lib_chan_mm:send(MM, {relay, Nick, Str})’. I understand this is received by mod_chat_controller which then forward it with ‘chat_server ! {mm, MM, Msg}’. so Msg is ‘{relay, Nick, Str}’. But when I look at server_loop, I see it only handles login messages by forwarding them to the group controller. Other messages seem to just be printed to the console (‘Msg’ pattern in server_loop). What have I missed? Thank you, |
Ittay Dror
2 posts
|
Maybe I found the answer. Does the call ‘controller(C, self())’ in chat_group.erl means that all messages from C will now be routed to the chat_group process (by lib_chan_mm)? If so, I think this function (controller) should be explained in the previous chapter. Also, I think the message diagram should define where each message goes (‘login’ goes to the chat_server process, ‘relay’ goes to the group controller) Another minor question is about server_loop’s handling of the login message. When it receives it and there’s no group controller, it creates one, but forgets about the message. So I assume this relies on the client’s behavior of resending login messages until acknowledged? If so, I think this should be pointed out (and why? why not start the group controller and then send it the login message? Thank you, |
Joe Armstrong
5 posts
|
You’re quite right – the call to controller/2 is the key to understanding everything. There is a much simpler example in the difficult to find “getting started” document at http://www.erlang.org/doc/getting_started/conc_prog.html#3.5 Cheers /Joe Armstrong |
3 posts, 2 voices
