[erlang-questions] Pinging the great unknown

Hugo Mills hugo@REDACTED
Wed May 18 23:12:54 CEST 2016


On Wed, May 18, 2016 at 04:40:36PM -0400, Donald Steven wrote:
> Hi all,
> 
> Simple newbie question for someone just learning.  I'm getting the hang of sending and receiving messages work and pids, but how does a process ping a message into the great unknown that says basically: "Hello out there, I'm here, I exist..." if you don't know what if any processes are 'out there' to actually receive a message?

   One approach: Process A (the receipient) registers itself with
register/2, using an atom as a name. Process B (the sender) uses the
same atom to look up the pid of A, with whereis/1. So, the initial
"connection" between the two comes from the programmer knowing that
process A registers under a particular name, and then telling process
B to use that name. There's a simple built-in registry (register/2,
whereis/1), or there are more complex third-party registries (like
gproc).

   Another approach: Process A starts. It starts process B, passing in
its own pid as a parameter.  Alternatively, process C could have
started both A and B, getting the pid of A after it's running, and
passing that to B as a parameter on startup.

   The first approach is more typical, particularly in the case where
process A is a server of some kind.

   Hugo.

-- 
Hugo Mills             | Be pure.
hugo@REDACTED carfax.org.uk | Be vigilant.
http://carfax.org.uk/  | Behave.
PGP: E2AB1DE4          |                                   Torquemada, Nemesis
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160518/bf7d7039/attachment.bin>


More information about the erlang-questions mailing list