When I run erl -sname foo
, the node name created uses the hostname, rather than "localhost", so it is generated as, for example, foo@roger-pc
.
I then register(shell, self())
, and I can send messages to it from another node (erl -sname bar
) as follows:
{shell, 'foo@roger-pc'} ! {hello, world}.
But it doesn't work if I use {shell, foo} ! {knock, knock}
. The message is never received.
How do I connect to an Erlang node on the same PC which is using a short name? Or: how do I derive the "@roger-pc" part of the destination node name? Or: should I just use erl -name foo@localhost
to register a long name?
Some background: I'm writing a an escript which spawns an erl
process, and I'd like to be able to send messages from that OS process back to the original script.
you can specify 'localhost' explicitly for sname.
first shell
erl -sname ax@localhost
register(rcvr, self()).
second shell
erl -sname bx@localhost
net_kernel:connect_node(ax@localhost).
{rcvr, ax@localhost} ! hello.
and first shell again
(ax@localhost)7> flush().
Shell got hello
ok
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With