I want to implement a simple chat room in which two nodes can send message to each other synchronous. There is not a node that plays a role of server.
Can I use !
to send a message to another node, if i have the pid of the process on this node by function of spawn(Node,Module,Fun,Args)
?
You can send to processes at another node just the same you would do with a process local to the same node. The trick is of course you need to have the process id. But you can also send to a process registered at another node by using the tuple {RegisteredName, NodeName}, e.g.
will send a message to yourself.The same syntax works across nodes.
A more elaborate example
In the first shell:
In the second shell:
And again in the first shell: