<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt"><div class="" style=""><span class="" style="">Hi,</span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;" class=""><span class="" style=""><br class="" style=""></span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;" class=""><span class="" style="">BEGINNER QUESTION ALERT</span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;" class=""><span
 class="" style=""><br class="" style=""></span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;" class=""><span class="" style="">I'm trying to create a file server that loops, responding to 2 requests: list_dir; and read_file. For some reason the server loops sometimes, but for some unknown reason after successfully  </span><span style="background-color: transparent;">responding to a read_file request does not receive/respond to any further requests.</span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;" class=""><span style="background-color: transparent;"><br></span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue,
 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;" class=""><span style="background-color: transparent;">I've studied this code extensively looking for my error, but to no avail. Could someone please put me out of my misery?</span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;" class=""><span style="background-color: transparent;"><br></span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;" class=""><span style="background-color: transparent;">Thanks,</span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida
 Grande', sans-serif; font-style: normal; background-color: transparent;" class=""><span style="background-color: transparent;"><br></span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;" class=""><span style="background-color: transparent;">Justin</span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal; background-color: transparent;" class=""><span class="" style=""><br></span></div><div style="background-color: transparent;" class="">-module(afile_server).</div><div style="background-color: transparent;" class="">-export([start/1]).</div><div style="background-color: transparent;" class=""><br class="" style=""></div><div style="background-color: transparent;" class="">start(Dir)
 -></div><div style="background-color: transparent;" class="">    spawn_loop_in_dir(Dir).</div><div style="background-color: transparent;" class=""><br class="" style=""></div><div style="background-color: transparent;" class="">spawn_loop_in_dir(Dir) -></div><div style="background-color: transparent;" class="">    Fn = fun() -> loop(Dir) end,</div><div style="background-color: transparent;" class="">    spawn(Fn).</div><div style="background-color: transparent;" class=""><br class="" style=""></div><div style="background-color: transparent;" class="">loop(Dir) -></div><div style="background-color: transparent;" class="">    receive</div><div style="background-color: transparent;" class="">        {Client, list_dir}          -> list_dir(Client, Dir);</div><div style="background-color: transparent;" class="">        {Client, {read_file,
 File}} -> read_file(Client, Dir, File)</div><div style="background-color: transparent;" class="">    end,</div><div style="background-color: transparent;" class="">    loop(Dir).</div><div style="background-color: transparent;" class=""><br class="" style=""></div><div style="background-color: transparent;" class="">list_dir(Client, Dir) -></div><div style="background-color: transparent;" class="">    Client ! prefix_with_self(list_dir_reply(Dir)).</div><div style="background-color: transparent;" class=""><br class="" style=""></div><div style="background-color: transparent;" class="">list_dir_reply(Dir) -></div><div style="background-color: transparent;" class="">    DirList = file:list_dir(Dir),</div><div style="background-color: transparent;" class="">    {list_dir, DirList}.</div><div style="background-color: transparent;" class=""><br class="" style=""></div><div style="background-color:
 transparent;" class="">read_file(Client, Dir, File) -></div><div style="background-color: transparent;" class="">    Client ! prefix_with_self(read_file_reply(Dir, File)).</div><div style="background-color: transparent;" class=""><br class="" style=""></div><div style="background-color: transparent;" class="">read_file_reply(Dir, File) -></div><div style="background-color: transparent;" class="">    Fullname = filename:join(Dir, File),</div><div style="background-color: transparent;" class="">    Contents = file:read_file(Fullname),</div><div style="background-color: transparent;" class="">    {read_file, Contents}.</div><div style="background-color: transparent;" class=""><br class="" style=""></div><div style="background-color: transparent;" class="">prefix_with_self(Msg) -></div><div style="background-color: transparent;" class=""><span class="" style=""></span></div><div style="background-color:
 transparent;" class="">    {self(), Msg}.</div><div class="" style=""><br class="" style=""></div><div class="" style=""></div><div class="" style=""> </div><div class="" style=""><br class="" style=""><span style="font-weight:bold;color:rgb(76, 118, 162);" class="">Justin</span><br class="" style=""><br class="" style=""><a rel="nofollow" target="_blank" href="http://180movie.com/" class="" style="">http://180movie.com/</a></div></div></body></html>