TCP is a cornerstone of building servers. Erlang/OTP provides the gen_tcp module for building TCP servers. We can take advantage of that module to build a TCP server in Elixir. Let's see what that looks like.

We'll start off by building a new project.

mix new tcp_server cd tcp_server

Now, we're not going to be test-driving this since it relies on inbound traffic to function. Instead, we're just going to write the TcpServer and then interact with it from telnet on the command line.

Open up lib/tcp_server/server.ex and just make a quick module that's going to house the TCP server.

defmodule TcpServer.Server do def listen(port) do IO.puts "listening on port #{port}" end end

Now, obviously this isn't actually listening yet :) Looking at the gen_tcp documentation, it houses a function called listen that takes two arguments: the port on which to listen, and the TCP options. The TCP options is a list of options. We want to say that the data received over...