Chapter 3. Writing a TCP-based RPC service
This chapter covers
- Introduction to OTP behaviors
- Module layout conventions and EDoc annotations
- Implementing an RPC server using TCP/IP
- Talking to your server over telnet
What!? No “hello world”?
That’s right, no “hello world.” In chapter 2, we provided a review of the Erlang language, and now it’s time to do something concrete. In the spirit of getting down and dirty with real-world Erlang, we say no to “hello world”! Instead, you’ll create something that is immediately useable. You’re going to build a TCP-enabled RPC server!
In case you don’t know what that is, let us explain. RPC stands for remote procedure call. An RPC server allows you to call procedures (that is, functions) remotely from another machine. The TCP-enabled RPC server will allow a person to connect to a running Erlang node, run Erlang commands, and inspect the results with no more than a simple TCP client, like good old Telnet. The TCP RPC server will be a nice first step toward making your software accessible for post-production diagnostics.
Source code
The code for this book is available online at GitHub. You can find it by visiting http://github.com/ and entering “Erlang and OTP in Action” in the search field. You can either clone the repository using git or download the sources as a zip archive.