Example usage for io.netty.handler.codec.http.websocketx WebSocketServerProtocolHandler WebSocketServerProtocolHandler

List of usage examples for io.netty.handler.codec.http.websocketx WebSocketServerProtocolHandler WebSocketServerProtocolHandler

Introduction

In this page you can find the example usage for io.netty.handler.codec.http.websocketx WebSocketServerProtocolHandler WebSocketServerProtocolHandler.

Prototype

public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions) 

Source Link

Usage

From source file:com.chuck.netty4.websocket.WebSocketServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }/*from  www  . jav  a 2s .c  om*/
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
    pipeline.addLast(new WebSocketIndexPageHandler(WEBSOCKET_PATH));
    pipeline.addLast(new WebSocketFrameHandler());
}

From source file:com.heliosapm.webrpc.server.RPCServer.java

License:Apache License

@Override
protected void initChannel(final SocketChannel ch) throws Exception {
    final ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
    pipeline.addLast(webSockServiceHandler);

}

From source file:com.hop.hhxx.example.http.websocketx.server.WebSocketServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }//from w  ww. j a  v a 2  s .  c  o  m
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
    pipeline.addLast(new io.netty.example.http.websocketx.server.WebSocketIndexPageHandler(WEBSOCKET_PATH));
    pipeline.addLast(new WebSocketFrameHandler());
}

From source file:com.im.test.WebSocketServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
    pipeline.addLast(new WebSocketFrameHandler());
}

From source file:com.metasoft.empire.net.websocket.WebSocketServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }/*from  ww w .  j ava 2 s. c  o  m*/
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    //webbrouser debug & benchmark
    //pipeline.addLast(new WebSocketIndexPageHandler(WEBSOCKET_PATH));
    //pipeline.addLast(new WebSocketServerHandler());
    //websocket protocal
    pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
    pipeline.addLast(WebSocketServer.context.getBean(WebSocketFrameHandler.class));

}

From source file:com.mpush.core.server.WebSocketServer.java

License:Apache License

@Override
protected void initPipeline(ChannelPipeline pipeline) {
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerProtocolHandler(CC.mp.net.ws_path, null, true));
    pipeline.addLast(new WebSocketIndexPageHandler());
    pipeline.addLast(getChannelHandler());
}

From source file:com.whizzosoftware.hobson.hub.websockets.WebSocketServerInitializer.java

License:Open Source License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new Authorizer(accessManager));
    pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
    pipeline.addLast(new WebSocketFrameHandler(clientChannels));
}

From source file:fr.kissy.zergling_push.MainServer.java

License:Apache License

private void run() throws Exception {
    final ChannelGroup allPlayers = new DefaultChannelGroup("AllPlayers", GlobalEventExecutor.INSTANCE);
    final ArrayBlockingQueue<PlayerMessage> messagesQueue = new ArrayBlockingQueue<PlayerMessage>(1024);

    final World world = new World();
    final MainLoop mainLoop = new MainLoop(world, allPlayers, messagesQueue);

    ScheduledThreadPoolExecutor mainLoopExecutor = new ScheduledThreadPoolExecutor(1);
    mainLoopExecutor.scheduleAtFixedRate(mainLoop, 0, TICK_RATE, TimeUnit.MILLISECONDS);

    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    EventExecutorGroup executorGroup = new DefaultEventExecutorGroup(16);

    try {/*ww w.  java 2 s  .  c o m*/
        final ServerBootstrap sb = new ServerBootstrap();
        sb.childOption(ChannelOption.TCP_NODELAY, true);
        sb.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(final SocketChannel ch) throws Exception {
                        ChannelPipeline pipeline = ch.pipeline();
                        pipeline.addLast("http-decoder", new HttpServerCodec());
                        pipeline.addLast("http-aggregator", new HttpObjectAggregator(65536));
                        pipeline.addLast("websocket-compression", new WebSocketServerCompressionHandler());
                        pipeline.addLast("websocket-protocol",
                                new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
                        pipeline.addLast(executorGroup, "flatbuffer-message",
                                new FlatBufferMessageHandler(world, messagesQueue));
                        pipeline.addLast("http-server", new HttpStaticFileServerHandler());
                    }
                }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);
        final Channel ch = sb.bind(8080).sync().channel();
        ch.closeFuture().sync();
    } catch (Exception e) {
        throw new RuntimeException("Error while running server", e);
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:org.apache.qpid.jms.transports.netty.NettyServer.java

License:Apache License

public void start() throws Exception {

    if (started.compareAndSet(false, true)) {

        // Configure the server.
        bossGroup = new NioEventLoopGroup(1);
        workerGroup = new NioEventLoopGroup();

        ServerBootstrap server = new ServerBootstrap();
        server.group(bossGroup, workerGroup);
        server.channel(NioServerSocketChannel.class);
        server.option(ChannelOption.SO_BACKLOG, 100);
        server.handler(new LoggingHandler(LogLevel.INFO));
        server.childHandler(new ChannelInitializer<Channel>() {

            @Override//w w  w  .j  a  v a  2s.  c  o m
            public void initChannel(Channel ch) throws Exception {
                if (options instanceof TransportSslOptions) {
                    TransportSslOptions sslOptions = (TransportSslOptions) options;
                    SSLContext context = TransportSupport.createSslContext(sslOptions);
                    SSLEngine engine = TransportSupport.createSslEngine(context, sslOptions);
                    engine.setUseClientMode(false);
                    engine.setNeedClientAuth(needClientAuth);
                    sslHandler = new SslHandler(engine);
                    ch.pipeline().addLast(sslHandler);
                }

                if (webSocketServer) {
                    ch.pipeline().addLast(new HttpServerCodec());
                    ch.pipeline().addLast(new HttpObjectAggregator(65536));
                    ch.pipeline().addLast(new WebSocketServerProtocolHandler(getWebSocketPath(), "amqp", true));
                }

                ch.pipeline().addLast(new NettyServerOutboundHandler());
                ch.pipeline().addLast(new NettyServerInboundHandler());
                ch.pipeline().addLast(getServerHandler());
            }
        });

        // Start the server.
        serverChannel = server.bind(getServerPort()).sync().channel();
    }
}

From source file:org.ballerinalang.test.util.websocket.server.WebSocketRemoteServerInitializer.java

License:Open Source License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }/*from   w  w  w .j  a va2 s.c o  m*/
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));

    WebSocketRemoteServerFrameHandler frameHandler = new WebSocketRemoteServerFrameHandler();
    FRAME_HANDLERS.add(frameHandler);
    pipeline.addLast(frameHandler);
}