Example usage for io.netty.util.concurrent GenericFutureListener GenericFutureListener

List of usage examples for io.netty.util.concurrent GenericFutureListener GenericFutureListener

Introduction

In this page you can find the example usage for io.netty.util.concurrent GenericFutureListener GenericFutureListener.

Prototype

GenericFutureListener

Source Link

Usage

From source file:vn.com.onesoft.bigfox.server.io.core.channel.websocket.WebSocketServerHandler.java

private void handleHttpRequest(final ChannelHandlerContext ctx, FullHttpRequest req) {
    //        if (req.uri().contains("vivulive"))
    //            ctx.channel().close();
    // Handshake/*www .  j  a  va  2  s.  com*/
    WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(getWebSocketLocation(req),
            null, true);
    handshaker = wsFactory.newHandshaker(req);
    if (handshaker == null) {
        WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
    } else {
        handshaker.handshake(ctx.channel(), req).addListener(new GenericFutureListener() {

            @Override
            public void operationComplete(Future f) throws Exception {
                Main.mapChannelWebSocket.put(ctx.channel(), Boolean.TRUE);
                BFLogger.getInstance().debug("Client connected!: " + ctx.channel());
                Main.allChannels.add(ctx.channel());
                Random r = new Random();
                int validationCode = r.nextInt();
                BFSessionManager.getInstance().sendMessage(ctx.channel(), new SCValidationCode(validationCode));
                BFEncryptManager.mapChannelToValidationCode.put(ctx.channel(), validationCode);
            }
        });
    }
}