title: Erlang: send file and filename
body: <p>I'm interesting to send a file and it's filename.
  Server's options:<br></p>
  
  <pre><code>-define(TCP_OPTIONS_SERVER, [binary, {packet, 0}, {active, false}]).
  </code></pre>
  
  <p>That's the receiver loop:<br></p>
  
  <pre><code>file_receiver_loop(Socket,Bs)-&gt;
  case gen_tcp:recv(Socket, 0) of
      {ok, B} -&gt;
          file_receiver_loop(Socket, [Bs, B]);
      {error, closed} -&gt;
          io:format("~nReceived!~n ~p",[Bs]),
          save_file(Bs)
  end.
  </code></pre>
  
  <p>I send file with:</p>
  
  <pre><code>file:sendfile(FilePath, Socket),
  </code></pre>
  
  <p>When I send file and filename</p>
  
  <pre><code>gen_tcp:send(Socket,Filename),
  file:sendfile(FilePath, Socket),
  </code></pre>
  
  <p>The Binary Data has a variable structure.<br></p>
  
  <p>Thanks all!</p>