1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| public class MyClientAioListener implements ClientAioListener {
Logger logger= LoggerFactory.getLogger(MyClientAioListener.class); private static Integer count=0;
@Override public void onAfterConnected(ChannelContext channelContext, boolean b, boolean b1) throws Exception { logger.info("onAfterConnected..."); }
@Override public void onAfterDecoded(ChannelContext channelContext, Packet packet, int i) throws Exception { logger.info("onAfterDecoded..."); }
@Override public void onAfterReceivedBytes(ChannelContext channelContext, int i) throws Exception { logger.info("onAfterReceivedBytes---------------------------"+i); }
@Override public void onAfterSent(ChannelContext channelContext, Packet packet, boolean b) throws Exception { logger.info("onAfterSent..."); }
@Override public void onAfterHandled(ChannelContext channelContext, Packet packet, long l) throws Exception { System.out.println("onAfterHandled..."); MyPacket clientPacket= (MyPacket) packet; String resData=new String(clientPacket.getBody(),"utf-8"); logger.info("[ "+channelContext.getServerNode()+" ] : "+resData); count++; ((MyPacket)packet).setBody(("[ "+channelContext.getServerNode()+" ]: "+count).getBytes(StandardCharsets.UTF_8)); Thread.sleep(5000); Tio.send(channelContext,packet); }
@Override public void onBeforeClose(ChannelContext channelContext, Throwable throwable, String s, boolean b) throws Exception { logger.error(throwable.getMessage()); logger.info(s); } }
|