Hello, Concurrency

We’ve seen how to compile a simple module. But what about writing a concurrent program? The basic unit of concurrency in Erlang is the process. A process is a lightweight virtual machine that can communicate with other processes only by sending and receiving messages. If you want a process to do something, you send it a message and possibly wait for a reply.

The first concurrent program we’ll write is a file server. To transfer files between two machines, we need two programs: a client that runs on one machine and a server that runs on a second machine. To implement this, we’ll make two modules called afile_client and afile_server.

The File Server Process

The file server is implemented in a module called afile_server. Just ...

Get Programming Erlang, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.