@Override
    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {

        // Generate and write a response.
        String response = "";
        boolean close = false;

        if (msg.isEmpty()) {
            response = "Please type something.";

        } else if ("help".equals(msg.toLowerCase())) {
            printHelp(ctx);

        } else if ("start".equals(msg.toLowerCase())) {
            start(ctx);

        } else if ("stop".equals(msg.toLowerCase())) {
            stop(ctx);

        } else if ("restart".equals(msg.toLowerCase())) {
            restart(ctx);

        } else if ("status".equals(msg.toLowerCase())) {
            status(ctx);

        } else if ("exit".equals(msg.toLowerCase())) {
            response = "Have a nice day!";
            close = true;

        } else {
            response = "I do not understand '" + msg + "'. Type 'help' for available commands.";
        }

        /* format response */
        String now = "[" + dateFormat.format(new Date()) + "] ";
        String respText;
        if (response.equals("")) {
            respText = now + PROMPT;
        } else {
            respText = now + response + NEWLINE + now + PROMPT;
        }

        // We do not need to write a ChannelBuffer here.
        // We know the encoder inserted at TelnetPipelineFactory will do the conversion.
        ChannelFuture future = ctx.write(respText);

        // Close the connection after sending 'Have a good day!'
        // if the client has sent 'bye'.
        if (close) {
            future.addListener(ChannelFutureListener.CLOSE);
        }

    }