My problem, is that this always times out on :gen_tcp.accept/2
iex(2)> {:ok, socket} = :gen_tcp.accept server, 1000
** (MatchError) no match of right hand side value: {:error, :timeout}
I’m wondering why I can’t seem to get this simple TCP server to accept connections? I was thinking that maybe there’s some option I need to specify to :gen_tcp.listen, but I haven’t had any luck trying different options out.
Are you sure you are getting a connection request to the listen socket (server) within the accept 1000 msec timeout? The return value {:error,:timeout} suggests that you are not.
You will get a better feel for how it works if you don’t do everything directly in the shell but use processes. Create a separate process which does listen, then accept and then recv, then prints the message and then terminates. Start that process then in the shell connect to the socket and send it a message.