title: How to download a file from a server
body: <p>I have a question with a general design implementation. Hope anyone more skilled than me helps me.</p>
  
  <p>I want to do an application based on an android client and a java server. Local wifi transmission, no 3G.</p>
  
  <p>Basically, the client must connect to the server and request a file to download using a code.</p>
  
  <p>How can I do that?</p>
  
  <p>Things I know:</p>
  
  <ul>
  <li>I must create a background thread in the client to create a file in the SD card and update a progress bar using a Handler to communicate with the UI thread.<br/><br/></li>
  <li>The server must be multithread and non-blocking.<br/><br/></li>
  <li>The file is a binary file like a mp3 audio. So the server has to:<br/><br/>
  <ol>
  <li>Send information about the file: name and total length.</li>
  <li>Open the file, read and send bytes while it does not reach the end.<br/><br/></li>
  </ol></li>
  <li>The client has to:<br/><br/>
  <ol>
  <li>Receive the information about the file and create an empty file.</li>
  <li>Read bytes and dump them into the empty file. Update progress bar.</li>
  <li>When all bytes are recieved close the file.</li>
  </ol></li>
  </ul>
  
  <p>I have knowledge implementing a client and server in C (very awful) but I am beginning with a real client-server application done in java.</p>
  
  <p>Questions:</p>
  
  <ul>
  <li><strong>How can I download a binary file like an mp3 from a server to a client?</strong><br/><br/></li>
  <li><strong>Where I have to put my server application? I supose that I must create a jar, save it on a folder and execute it at PC start-up, right?</strong></li>
  </ul>
  
  <p>Thanks!</p>