コード例 #1
0
 @Override
 public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
   Channel channel = ctx.getChannel();
   if (!sessions.removeSession(channel.getId())) {
     Log.error("删除Session失败! sockId: " + channel.getId());
   }
 }
コード例 #2
0
 @Override
 public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
   ChannelBuffer buffer = (ChannelBuffer) e.getMessage();
   Route route = app.getRouter().parseRoute(getUtf(buffer));
   byte[] data = new byte[buffer.readableBytes()];
   buffer.readBytes(data);
   LocalSession localSession = sessions.getSession(ctx.getChannel().getId()).getLocalSession();
   byte[] response = server.handle(route, localSession, data);
   if (response != null) {
     ctx.getChannel().write(response);
   }
 }
コード例 #3
0
 @Override
 public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
   Channel channel = ctx.getChannel();
   sessions.createSession(channel.getId(), frontendId, channel);
 }