<div dir="ltr"><div>I incorporated the suggestions and it solved the issue of setting up a socket to listen on a specified port(line 5). However, a new issue has risen while attempting to accept a connection on the listening socket. The error message follows:<br>
<br>=ERROR REPORT==== 18-Dec-2013::17:32:47 ===<br>Error in process <0.32.0> with exit value: {{badmatch,{error,closed}},[{mock_tcp,connect,2,[{file,"mock_tcp.erl"},{line,12}]}]}<br><br></div><div>I'm starting the server via erl -s mock_tcp start 8080 <path_to_file><br>
</div><div><br>-module(mock_tcp).<br>-export([start/1]).<br><br>start([AtomPort, AtomFilename]) -><br> Port = list_to_integer(atom_to_list(AtomPort)),<br> Filename = atom_to_list(AtomFilename),<br> {ok, Listen} = gen_tcp:listen(Port, [binary, {reuseaddr, true}]),<br>
spawn(fun() -> connect(Listen, Filename) end),<br> io:format("Server available on port ~p. Reading from file ~p.", [Port, Filename]).<br><br>connect(Listen, Filename) -><br></div> % Following line causes the error<br>
<div> {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>