With Joe Armstrong's new book, Programming Erlang, out in beta form I think I need to visit Erlang again. My first (and last) endeavor was a short and sweet reverser server:
-module(reverser). -export([start/1]). handle_connection(ClientSock) -> case gen_tcp:recv(ClientSock, 0) of {ok, Stuff} -> gen_tcp:send(ClientSock, lists:reverse(Stuff)), handle_connection(ClientSock); {error, Reason} -> exit(Reason) end. server_accept(ServerSock) -> {ok, ClientSock} = gen_tcp:accept(ServerSock), Pid = spawn(fun() -> handle_connection(ClientSock) end), gen_tcp:controlling_process(ClientSock, Pid), server_accept(ServerSock). start(Port) -> {ok, ServerSock} = gen_tcp:listen(Port, [list, {active, false}]), spawn(fun() -> server_accept(ServerSock) end).
At the time I was very impressed with Erlang's available documentation -- I was able to make that from not knowing anything in just a couple hours, and it worked! O frabjous day!
I'm only about 50 or 60 pages into Joe's book, but those pages, at least, are extremely well written and make clear not only how to do things but what Erlang is actually doing under the covers (to some degree) which makes a world of difference.