[erlang-questions] Simple TCP Server

Ari King ari.brandeis.king@REDACTED
Tue Dec 17 19:53:37 CET 2013


The code below results in "init terminating in do_boot." Seemingly the
problem is on line 5, does anyone see what is wrong with it? Additionally,
I'm trying to pass the port in as a command line argument, but for some
reason it doesn't work and I need to hardcode it.


start([Port, Filename]) ->
  {ok, Listen} = gen_tcp:listen(Port, [binary]),
  spawn(fun() -> connect(Listen, Filename) end),
  io:format("Server available on port ~w. Reading from file ~w.", [Port,

connect(Listen, Filename) ->
  {ok, Socket} = gen_tcp:accept(Listen),
  spawn(fun() -> connect(Listen, Filename) end),
  {ok, Device} = file:open(Filename, read),
  get_data(Device, Socket).

get_data(Device, Socket) ->
  case io:get_line(Device) of
    {ok, Data} ->
      gen_tcp:send(Socket, Data),
      get_data(Device, Socket);
    eof ->


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20131217/c57c4a86/attachment.htm>

More information about the erlang-questions mailing list