com.cdg.study.netty.discard.DiscardServerHandler.java Source code

Java tutorial

Introduction

Here is the source code for com.cdg.study.netty.discard.DiscardServerHandler.java

Source

/*
 * @(#)DiscardServerHandler.java $version 2015. 8. 19.
 *
 * Copyright 2015 NHN Ent. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package com.cdg.study.netty.discard;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * Netty 
 * 
 * @author Kanghoon Choi
 */
public class DiscardServerHandler extends ChannelInboundHandlerAdapter { // ? ? ? 

    @Override
    public void channelRead(ChannelHandlerContext context, Object msg) { // Netty? ?? 
        ByteBuf buf = (ByteBuf) msg; // ??   ?? ?
        try {
            while (buf.isReadable()) { // (1)
                System.out.print((char) buf.readByte());
                System.out.flush();
            }
        } finally {
            buf.release(); //  ?  ? 
        }
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { // 
        cause.printStackTrace();
        ctx.close();
    }
}