Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.witjit.game.server.communication.handler; import com.witjit.game.server.communication.ClientSessionPoint; import com.witjit.game.server.communication.MessageID; import com.witjit.game.server.communication.channel.ChannelData; import com.witjit.game.server.communication.channel.ClientChannelData; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; /** * * @author Administrator */ public class ClientDispatchHandler extends ChannelInboundHandlerAdapter { /** * * @param ctx * @param msg * @throws Exception */ @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (!(msg instanceof ByteBuf)) { //TODO: handle error message. return; } ByteBuf mb = (ByteBuf) msg; byte target = mb.readByte(); short id = mb.readShort(); mb.discardReadBytes(); ClientChannelData channelData = ChannelData.get(ctx.channel()); ClientSessionPoint sessionPoint = channelData.getBindSessionPoint(); sessionPoint.transit(target, MessageID.make(id), msg); } }