public boolean sendFile(FileMeta meta, File file) throws IOException {
        if (socket == null) {
            throw new IllegalStateException("No open connection!");
        }

        logger.debug("Pushing new file: ");
        socket.getOutputStream().write(ConnectionMessages.SERVER_FILE_PUSH.getBytes());
        socket.getOutputStream().flush();

        // Push the meta (size (as long) - date itself)
        byte[] jsonobj = meta.toJSON().toJSONString().getBytes();
        byte[] objsizebytes = Utilities.longToBytes((long) jsonobj.length);

        socket.getOutputStream().write(objsizebytes);
        socket.getOutputStream().flush();
        socket.getOutputStream().write(jsonobj);
        socket.getOutputStream().flush();

        // Clear buffers
        jsonobj = null;
        objsizebytes = null;

        int response = socket.getInputStream().read();

        if (response == ConnectionMessages.SERVER_FILEPUSH_ACCEPT) {
            logger.debug(" File was accepted");

            OutputStream output = socket.getOutputStream();

            // Send the filesize
            long filesize = file.length();
            logger.debug(" bytes to transfer: " + filesize);
            // Write the filesize
            output.write(Utilities.longToBytes(filesize));
            output.flush();

            // Prepare databuff
            byte[] bytearray = new byte[BUFFER_SIZE];

            FileInputStream fin = null;
            BufferedInputStream bin = null;
            try {
                // load the file into the databuffer array
                fin = new FileInputStream(file);
                bin = new BufferedInputStream(fin);

                // Sending the data in chunks
                int length;
                while ((length = bin.read(bytearray)) != -1) {
                    output.write(bytearray, 0, length);
                    output.flush();
                }
                logger.debug("File transfer complete!");
            } finally {
                try {
                    if (fin != null) {
                        fin.close();
                    }
                } catch (IOException ex) {
                }
                try {
                    if (bin != null) {
                        bin.close();
                    }
                } catch (IOException ex) {
                }
            }
            logger.debug(" File transfer complete!");
            return true;
        } else if (response == ConnectionMessages.SERVER_FILEPUSH_DUPELICATE) {
            logger.debug(" File is a duplicate of an existing file!");
            return true;
        } else if (response == ConnectionMessages.SERVER_FILEPUSH_NOFREESPACE) {
            logger.debug(" Server has no free space");
        } else {
            logger.error("Server gave an invalid response...!");
        }
        return false;
    }