title: A simple web-server is not working after switching to multithread in Erlang
body: <p>Here's the code for <strong>rudy.erl</strong>:</p>
  
  <pre><code>-module(rudy).
  -export([init/1,handler/1,request/1,reply/2, start/1, stop/0]).
  
  start(Port) -&gt;
    register(rudy, spawn(fun() -&gt;
      init(Port) end)).
  
  stop() -&gt;
    exit(whereis(rudy), "time to die").
  
  init(Port) -&gt;
    Opt = [list, {active, false}, {reuseaddr, true}],
    case gen_tcp:listen(Port, Opt) of         % opens a listening socket
      {ok, Listen} -&gt;
        handler(Listen),
        gen_tcp:close(Listen),            % close the socket
        ok;
      {error, _Error} -&gt; error
    end.
  
  handler(Listen) -&gt;
    case gen_tcp:accept(Listen) of            % listen to the socket
      {ok, Client} -&gt;
        request(Client),
        gen_tcp:close(Client),
        handler(Listen);
      {error, _Error} -&gt; error
    end.
  
  request(Client) -&gt;
    Recv = gen_tcp:recv(Client, 0),
    case Recv of
      {ok, Str} -&gt;
        Request = http:parse_request(Str),
  %%       spawn(rudy, reply, [Client, Request]);
        reply(Client, Request);
      {error, Error} -&gt;
        io:format("rudy: error: ~w~n", [Error])
    end.
  
  
  reply(Client, {{get, URI, _}, _, _}) -&gt;
    timer:sleep(40),
    Response = http:ok(URI),
    gen_tcp:send(Client, Response),
    gen_tcp:close(Client).
  </code></pre>
  
  <p>If I execute <code>rudy:start(8027)</code>, it will work normally via accessing <strong><a href="http://localhost:8027/" rel="nofollow">http://localhost:8027/</a></strong>, but if I convert <code>reply(Client, Request);</code> to <code>spawn(rudy, reply, [Client, Request]);</code>, the preceding URL could not be accessed with no error output to command line. </p>
  
  <p>What's the possible problem here? Thanks in advance.</p>