There are two models of Erlang distributed programming
First, distributed Erlang
Running in a trusted network environment
1. Remote procedure call provided by RPC
Rpc:call (Node,mode,fun,args)->result| {Badrpc,reason}
2. Functions in global can be used to register names and locks in distributed systems, and to maintain a fully connected network
Spawn (Node,fun), Pid
Spawn (Node,mode,fun,args)->pid
Spawn_link (Node,fun), Pid
Spawn_link (Node,mode,fun,args)->pid
Disconnect_node (node)->bool () |ignored
Monitor_node (Node,flag)->true
If flag is true, monitoring is turned on, and flag is false to turn off monitoring. If monitoring is turned on, then when
When node joins or leaves the Erlang Interconnect node group, the process that executes the built-in function receives {nodeup, node}
or {nodedown, Node} message.
Nodes ()->[node]
Node ()->node
It returns the name of the local node. If the node is not distributed, it will return [email protected].
Node (ARG)->node
It returns the node where Arg is located. Arg can be a PID, reference, or port. If the local node is not distributed,
[email protected] will be returned.
Is_alive ()->bool ()
Returns true if the local node is active and can be part of a distributed system, otherwise false is returned.
{Regname,node}! Msg
Send can be used to send messages to a set of locally registered processes in a distributed Erlang node
Second, the distributed model based on socket
TCP can password protect services by creating two agent processes, one client, one server side, converting Erlang messages to TCP packet data, and sending and receiving messages over the TCP protocol.
Erlang Distributed programming Model