Is my HTTP protocol design correctly implemented in the coding? <p>It's my very simple client-server application. Client sends some commands to the server and server gives back the output to the client. However, my special concern is about the <code>GET</code> command sent to the server. The client request <code>GET filename</code> to download a named file. That file ultimately gets downloaded into the client directory with the HTTP response headers, as I have designed my protocol.</p> <p>Now I am afraid if my coding follows the protocol accurately. Especially the HTTP response headers with the Line break (in both client and server side).</p> <p>PROTOCOL DESIGN:</p> <p>Client:</p> <pre><code>syntax: GET namedfile CRLF CRLF meaning: downloading the named file from the server representation: text file </code></pre> <p>server:</p> <pre><code>syntax: Status: ok CRLF Length: 20 bytes CRLF CRLF File contents meaning: The file exist in the server and ready to download representation: text file </code></pre> <p>CODE:</p> <p>ServerSide:</p> <pre><code> ................. ................. else if (request.startsWith("GET")) { System.out.println(""); String filename = request.substring(4); File file = new File(System.getProperty("user.dir")); File[] files = file.listFiles(); if (fileExists(files, filename)) { file = new File(filename); int fileSize = (int) file.length(); outputToClient.print("Status OK\r\n" + "Size " + fileSize + "KB" + "\r\n" + "\r\n" + "File " + filename + " Download was successfully\r\n"); outputToClient.flush(); // reading files fis = new FileInputStream(file); os = socket.getOutputStream(); byte[] buffer = new byte[2^7-1]; int bytesRead = 0; while ((bytesRead = fis.read(buffer))!= -1) { os.write(buffer, 0, bytesRead); } os.close(); fis.close(); } else { outputToClient.print("Status 400\r\n" + "File " + filename + " not found\r\n" + "\r\n"); outputToClient.flush(); } } outputToClient.flush(); } ................. ................. </code></pre> <p>ClientSide:</p> <pre><code> ............ ............ if (request.startsWith("GET")) { File file = new File(request.substring(4)); is = socket.getInputStream(); fos = new FileOutputStream(file); byte[] buffer = new byte[socket.getReceiveBufferSize()]; int bytesReceived = 0; while ((bytesReceived = is.read(buffer)) &gt;=0) { //while ((bytesReceived = is.read(buffer))&gt;=buffer) { fos.write(buffer, 0, bytesReceived); } request = ""; fos.close(); is.close(); } ................. ................. </code></pre>