public static void recv(Socket socket) {
        try {
            PrintWriter server = new PrintWriter(socket.getOutputStream());
            int numFiles = Integer.parseInt(readLine(socket));
            System.out.println("Receiving " + numFiles + " files...");

            for( int i = 0; i < numFiles; i++){
                // Get the file's name
                String fileName = readLine(socket);
                System.out.println("Receiving file " + fileName);
                File file = new File(fileName);

                // Check if we have a file by the same name here
                if(file.exists()){
                    System.out.println("File " + file + " already exists");
                    server.println(EXISTS);
                    server.flush();
                    // Get what the server computes for the digest of the file
                    String hexDigest = readLine(socket);
                    String ourHexDigest = getMD5Digest(file);

                    if(hexDigest.equals(ourHexDigest)){
                        System.out.println("Already have file " + fileName + " Cached...skipping");
                        server.println(CACHED);
                        server.flush();
                        continue;
                    }
                }
                // Accept the file
                server.println(ACCEPT);
                server.flush();
                BufferedOutputStream binWriter = new BufferedOutputStream(new FileOutputStream(file));
                // Read this files size
                long fileSize = Integer.parseInt(readLine(socket));

                // Read the block size they are going to use
                int blockSize = Integer.parseInt(readLine(socket));
                byte[] buffer = new byte[blockSize];

                long bytesLeft = fileSize;
                int read = 0;

                while(bytesLeft != 0){
                    // Read the min of the bytesLeft and blocksize
                    read = socket.getInputStream().read(buffer, 0, bytesLeft < blockSize ? (int)bytesLeft : blockSize );
                    binWriter.write(buffer,0,read);
                    bytesLeft -= read;
                    //System.out.println(bytesLeft + " bytes left");
                }
                binWriter.flush();
                binWriter.close();
                System.out.println("Done with " + fileName);
            }
        } catch (IOException e) {
            System.err.println("Socket I/O Error when transfering file ");
        }
    }