/** * Copyright (c) 2013 by 苏州科大国创信息技术有限公司. */ package com.ustcinfo.netty.object.simple; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import java.util.logging.Level; import java.util.logging.Logger; /** * Handles both client-side and server-side handler depending on which * constructor was called. * * Create on @2013-8-15 @上午10:10:38 * @author bsli@ustcinfo.com */ public class ObjectEchoServerHandler extends ChannelInboundHandlerAdapter { private static final Logger logger = Logger.getLogger(ObjectEchoServerHandler.class.getName()); @Override public void channelRead( ChannelHandlerContext ctx, Object msg) throws Exception { // Echo back the received object to the client. ctx.write(msg); } @Override public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { ctx.flush(); } @Override public void exceptionCaught( ChannelHandlerContext ctx, Throwable cause) throws Exception { logger.log( Level.WARNING, "Unexpected exception from downstream.", cause); ctx.close(); } }