<div dir="ltr">Hi,<br><div><br>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. <br>
<br>-module(mock_tcp).<br>-export([start/1]).<br><br>start([Port, Filename]) -><br> {ok, Listen} = gen_tcp:listen(Port, [binary]),<br> spawn(fun() -> connect(Listen, Filename) end),<br> io:format("Server available on port ~w. Reading from file ~w.", [Port, Filename]).<br>
<br>connect(Listen, Filename) -><br> {ok, Socket} = gen_tcp:accept(Listen),<br> spawn(fun() -> connect(Listen, Filename) end),<br> {ok, Device} = file:open(Filename, read),<br> get_data(Device, Socket).<br><br>get_data(Device, Socket) -><br>
case io:get_line(Device) of<br> {ok, Data} -><br> gen_tcp:send(Socket, Data),<br> get_data(Device, Socket);<br> eof -> <br> file:close(Device),<br> gen_tcp:close(Socket)<br> end.<br><br>
</div><div>Thanks.<br><br></div><div>-Ari<br></div></div>