erlang遠端呼叫示例

2021-09-23 23:17:16 字數 1225 閱讀 4884

下面的例子試用了erlang的分布式程式設計,從中可以看出像erlang這種基於訊息的純函式語言在分布式程式設計中的強大威力.

在遠端節點編寫乙個測試的模組

-module(distribution).

-export([a/0]).

a() ->

hello.

首先啟動遠端節點,並設定cookie,載入模組

$ erl -name remote -setcookie abc

erlang r16b03 (erts-5.10.4) [source] [64-bit] [async-threads:10] [kernel-poll:false]

eshell v5.10.4  (abort with ^g)

([email protected])1> c(distribution).

啟動本地節點,設定同樣的cookie

$ erl -name [email protected] -setcookie abc

erlang/otp 18 [erts-7.0] [source] [64-bit] [smp:2:2] [async-threads:10] [kernel-poll:false]

eshell v7.0  (abort with ^g)

([email protected])1> rpc:call('[email protected]',distribution,a,).

hello

要點1.本地的長name,不能只寫client,需要加上位址

編寫乙個模組

-module(remote_local).

-export([start/1,echo/2]).

start(node)-> spawn(node,fun()->loop() end).

loop()->

receive

->

from!,

loop()

end.

echo(pid,request)->

pid!,

receive

->

response

end.

檢視遠端的cookie

$ cat ~/.erlang.cookie

felwzvcnjefsimpprbd   

設定本地cookie和遠端一樣,並注意檔案方法許可權

啟動遠端節點,並載入模組

啟動本地節點載入模組,測試

erlang接入遠端shell

兩種方式 erl name aaa 127.0.0.1 setcookie 111 erl name bbb 127.0.0.1 setcookie 111 ctrl g進入jcl模式 h檢視幫助r aaa 127.0.0.1 j檢視job列表 c 2進入遠端shell 如果返回,則重新ctrl g...

Windows API 呼叫示例

簡介 本文主要記錄windows api 的呼叫示例,因為這項技術並不常用,屬於c 中比較孤僻或接觸底層的技術,並不常用。但是有時候也可以借助他完成一些c 本身不能完成的功能,例如 通過控制代碼獲取其他程式資料,或者向作業系統發出指定的訊息等等。1.滑鼠事件api 1 函式原型 void mouse...

erlang 接入遠端shell控制台

erlang shell是使用者與 erlang 執行時系統互動的介面程式。事實上,erlang vm的執行不依賴任何shell,只要在啟動的時候新增引數detached就可以脫離終端。detached starts the erlang runtime system detached from t...