The Chat application is pretty simple. It sends messages to remote nodes and remote nodes respond to those messages by IO.puts-ing them out to the STDOUT of the remote node.
In one terminal window, start up our chat app in a named iex session
iex --sname alex@localhost -S mixOpen up another terminal window to start the app on a different named node:
iex --sname kate@localhost -S mixNow, from the alex node, we can send a message to the kate node:
iex(alex@localhost)> Chat.send_message(:kate@localhost, "hi")
:okSwitch to the kate window and you should see the message:
iex(kate@localhost)> hiThe kate node can respond back to the alex node:
iex(kate@localhost)> hi
Chat.send_message(:alex@localhost, "how are you?")
:ok
iex(kate@localhost)>
And it will show up in the alex node’s iex session:
iex(alex@localhost)> how are you?Let's have another node named moebi
iex --sname moebi@localhost -S mixLet’s have alex send a message to moebi:
iex(alex@localhost)> Chat.send_message(:moebi@localhost, "hi")
chicken?
:okWe can see that the alex node received the response, "chicken?". If we open the kate node, we’ll see that no message was received, since neither alex nor moebi send her one (sorry kate). And if we open the moebi node’s terminal window, we’ll see the message that the alex node sent:
iex(moebi@localhost)> hi