6

I want to be able to have two Erlang shells to talk. I'm running on OS X.

I tried the tut17 example here.

I've also tried:

$ erl -sname foo

and then in a new Terminal:

$ erl -sname bar

(bar@elife)1> net_adm:ping(foo@elife).
pang

Any ideas?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Eli
  • 1,269
  • 8
  • 17

3 Answers3

10

It's kind of broken on the mac. By default, the mac can't resolve its own shortname. Your host's name is really probably "elife.local".

If you start erl with -name FQDN, then the pings will work.

ie: you would start it with

$ erl -name foo@elife.local

this probably could be fixed by making the mac capable of resolving it's own short name

Here's example output from my mac. When I do -sname I get the same result as you.

The first node:

$ erl -name foo@mookie.local
Erlang R13B03 (erts-5.7.4) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]

Eshell V5.7.4  (abort with ^G)
(foo@mookie.local)1> 

The other node:

$ erl -name bar@mookie.local
Erlang R13B03 (erts-5.7.4) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]

Eshell V5.7.4  (abort with ^G)
(bar@mookie.local)1> net_adm:ping('foo@mookie.local').
pong
David Budworth
  • 11,248
  • 1
  • 36
  • 45
  • If anyone is getting this error, * 1: syntax error before: '.', then be sure to wrap the name in single quotes. net_adm:ping('foo@mookie.local'). – Coderdad Mar 11 '13 at 21:01
4

A simpler fix might just be editing your /etc/hosts file and make sure you have something like this line:

127.0.0.1 localhost elife

My mac works fine with shortnames, and I believe this is what did it.

Jacob
  • 4,204
  • 1
  • 25
  • 25
  • 2
    This is the correct answer. Erlang resolves names to IP addresses just like anything else. As a general principle your `net_adm:ping` will not work if a regular icmp `ping` sent to the same name is not answered. – Zed Jan 26 '10 at 07:32
  • aside from OSX ignores the hosts file. there's another place to set it on the mac, can't remember where. edit: at least it did originally, haven't tried under Snow Leopard – David Budworth Jan 27 '10 at 12:37
  • also, setting 127.0.0.1 to resolve as your hostname will break a lot of java apps (any app that uses RMI). normally, you want your hostname to point to your "public" ip addr. – David Budworth Jan 27 '10 at 12:41
  • yes, your hostname to /etc/hosts makes "-sname" works on Snow Leopard (I tried). But has the drawback for things that actually try to resolve their own hostname (ie: Java RMI) – David Budworth Jan 28 '10 at 13:09
0

For the nodes communicate with each other, both should have the same cookie. On the same box it works as it end up using the cookie from $HOME/.erlang.cookie file. If this file is not present, it create a new file and put some random cookie in it. Future shells use the same cookie. But it is always better to specify the cookie on the command line via setcookie parameter.

erl -name node1@foo.local -setcookie mycookie

  • 1
    It is not better to set cookie via command line argument, because other users on the same system will be able to know your cookie just viewing process list, and after that malicious user will be able to send messages to your erlang nodes. If you store cookies in the file, do not forget to set proper permissions on that file. – taro Aug 17 '10 at 07:38