<div dir="ltr"><div style="font-family:arial,sans-serif;font-size:13px">I've just started with Erlang and to learn/practice I'm attempting to put together a simple TCP server that reads data from a file and writes it to a socket. So far I've put together some code to read the data (combination of ascii, binary, control characters). But since (as I understand) Erlang doesn't have a return mechanism, how do I read a line of data and return it to be written to the socket? Right now, the code just recursively collects the data.<br>
<br> -module(mock_tcp).<br> -export([start/1]).<br> <br> start([Ip, Port, Filename]) -><br> io:format("Server available at ~w on port ~w. Reading from ~w.", [Ip, Port, Filename]),<br> {ok, Device) = file:open(Filename, read),<br>
try get_data(Device)<br> after file:close(Device)<br> end.<br> <br> get_data(Device) -><br> case io:get_line(Device) of<br> {ok, Data} -> [Data | get_data(Device)];<br> eof -> []<br>
end.<br><br></div><span style="font-family:arial,sans-serif;font-size:13px">Thanks.</span><br><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">Ari</span></div>
</div>