@Override public void parseCommand(String[] message, ChannelHandlerContext ctx) { String password = message[0]; if (password.equals("cometServer")) { String command = message[1]; switch (command) { default: { ctx.channel().writeAndFlush("response||You're connected!"); break; } case "stats": { ctx.channel() .writeAndFlush("response||" + JsonFactory.getInstance().toJson(CometStats.get())); break; } } } else { ctx.disconnect(); } }
@Override public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { if (side == Side.CLIENT) { FMLCommonHandler.instance() .bus() .post(new FMLNetworkEvent.ClientDisconnectionFromServerEvent(manager)); } else { FMLCommonHandler.instance() .bus() .post(new FMLNetworkEvent.ServerDisconnectionFromClientEvent(manager)); } cleanAttributes(ctx); ctx.disconnect(promise); }
private void closeOutboundAndChannel( final ChannelHandlerContext ctx, final ChannelFuture future, boolean disconnect) throws Exception { if (!ctx.channel().isActive()) { if (disconnect) { ctx.disconnect(future); } else { ctx.close(future); } return; } engine.closeOutbound(); ChannelFuture closeNotifyFuture = ctx.newFuture(); flush(ctx, closeNotifyFuture); safeClose(ctx, closeNotifyFuture, future); }
private void closeOutboundAndChannel( final ChannelHandlerContext ctx, final ChannelPromise promise, boolean disconnect) throws Exception { if (!ctx.channel().isActive()) { if (disconnect) { ctx.disconnect(promise); } else { ctx.close(promise); } return; } engine.closeOutbound(); ChannelPromise closeNotifyFuture = ctx.newPromise(); write(ctx, Unpooled.EMPTY_BUFFER, closeNotifyFuture); flush(ctx); safeClose(ctx, closeNotifyFuture, promise); }
@Override public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { ctx.disconnect(promise); }