Beispiel #1
0
 @Override
 public void handle(DeviceMsg jsonObject, HandlerChain handlerChain, Channel channel) {
   index++;
   if (index <= max) {
     handlerList.get(index).handle(jsonObject, handlerChain, channel);
     index = -1;
   } else {
     LOG.error("无法处理的客户端消息: {}", jsonObject.toString());
   }
 }
  @Override
  protected void channelRead0(ChannelHandlerContext ctx, DeviceMsg s) throws Exception { // (4)
    Channel incoming = ctx.channel();
    for (Channel channel : channels) {
      /*if (channel != incoming) {
          //向其他终端写入消息
          s.setMsg("server msg");
          channel.writeAndFlush(s);
      } else {
          //向自己终端写入消息
          channel.writeAndFlush("[you]" + s + "\n");
      }*/

    }
    s.setMsg("server msg");
    incoming.writeAndFlush(s);
  }