簡體   English   中英

如何連接到使用短名稱的Erlang節點?

[英]How do I connect to an Erlang node which uses a short name?

當我運行erl -sname foo ,創建的節點名稱使用主機名而不是“localhost”,因此它被生成為例如foo@roger-pc

然后我register(shell, self()) ,我可以從另一個節點( erl -sname bar )向它發送消息,如下所示:

{shell, 'foo@roger-pc'} ! {hello, world}.

但是如果我使用{shell, foo} ! {knock, knock}它就行不通{shell, foo} ! {knock, knock} {shell, foo} ! {knock, knock} 永遠不會收到該消息。

如何連接到使用短名稱的同一台PC上的Erlang節點? 或者:如何導出目標節點名稱的“@ roger-pc”部分? 或者:我應該使用erl -name foo@localhost來注冊長名嗎?

一些背景:我正在編寫一個生成erl進程的escript,我希望能夠將該OS進程的消息發送回原始腳本。

你可以為sname明確指定'localhost'。

第一個殼

erl -sname ax@localhost
register(rcvr, self()).

第二個殼

erl -sname bx@localhost
net_kernel:connect_node(ax@localhost).
{rcvr, ax@localhost} ! hello.

再來一次炮彈

(ax@localhost)7> flush().
Shell got hello
ok

sname仍然需要'@'表示法。 您只需在發送郵件時輸入完整的uri即可。

c:\>erl -sname short
(short@hostname)1> {process, 'short@hostname'} ! Message.

c:\>erl -name short
(short@hostname.more.stuff)1> {process, 'short@hostname.more.stuff'} ! Message.

簡短不是全名。 sname和name只決定需要多少路徑的其余部分。

節點是一個執行的Erlang運行時系統,它使用命令行flag -name(長名稱)或-sname(短名稱)給出了名稱。

節點名稱的格式是原子名稱@ host,其中name是用戶指定的名稱,host是使用長名稱時的完整主機名,如果使用短名稱,則是主機名的第一部分。 node()返回節點的名稱。 例:

%erl -name dilbert(dilbert@uab.ericsson.se)1> node()。 'dilbert@uab.ericsson.se'

%erl -sname dilbert(dilbert @ uab)1> node()。 迪爾伯特@ UAB

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM