title: How to send a message through TCP protocol to a TCP server using gen_tcp in Elixir?
body: <p>I have 2 elixir applications.</p>
  <p>In one of them I create a TCP server which listens on the port 8080 for packets. I know that it is defined correctly, because I connected to it with telnet and everything was working fine.</p>
  <p>The problem appears when I try to connect to this TCP server from my other Elixir application.</p>
  <p>That's how I connect to it</p>
  <pre><code>host = 'localhost'
  {:ok, socket} = :gen_tcp.connect(host, 8080, [])
  </code></pre>
  <p>Not sure about the options that I should specify tho.</p>
  <p>When trying to connect to it I get in the logs of the application with TCP server:</p>
  <pre><code>00:21:11.235 [error] Task #PID&lt;0.226.0&gt; started from MessageBroker.Controller terminating
  ** (MatchError) no match of right hand side value: {:error, :closed}
      (message_broker 0.1.0) lib/message_broker/network/controller.ex:110: MessageBroker.Controller.read_line/1
      (message_broker 0.1.0) lib/message_broker/network/controller.ex:101: MessageBroker.Controller.serve/1
      (elixir 1.12.3) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
      (stdlib 3.12) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
  Function: #Function&lt;0.126110026/0 in MessageBroker.Controller.loop_acceptor/1&gt;
      Args: []
  </code></pre>
  <p>At the line with</p>
  <pre><code>{:ok, data} = :gen_tcp.recv(socket, 0)
  </code></pre>
  <p>Any ideas, suggestions?</p>