Search in sources :

Example 11 with ChannelPipeline

use of io.netty.channel.ChannelPipeline in project netty-socketio by mrniko.

the class SocketIOChannelInitializer method initChannel.

@Override
protected void initChannel(Channel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    addSslHandler(pipeline);
    addSocketioHandlers(pipeline);
}
Also used : ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 12 with ChannelPipeline

use of io.netty.channel.ChannelPipeline in project neo4j by neo4j.

the class TransportSelectionHandler method switchToWebsocket.

private void switchToWebsocket(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();
    p.addLast(new HttpServerCodec(), new HttpObjectAggregator(MAX_WEBSOCKET_HANDSHAKE_SIZE), new WebSocketServerProtocolHandler("/"), new WebSocketFrameTranslator(), new SocketTransportHandler(new ProtocolChooser(protocolVersions, encryptionRequired, isEncrypted), logging));
    p.remove(this);
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) WebSocketServerProtocolHandler(io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 13 with ChannelPipeline

use of io.netty.channel.ChannelPipeline in project neo4j by neo4j.

the class TransportSelectionHandler method enableSsl.

private void enableSsl(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();
    p.addLast(sslCtx.newHandler(ctx.alloc()));
    p.addLast(new TransportSelectionHandler(null, encryptionRequired, true, logging, protocolVersions));
    p.remove(this);
}
Also used : ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 14 with ChannelPipeline

use of io.netty.channel.ChannelPipeline in project netty by netty.

the class MemcacheClient method main.

public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {
        sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
    } else {
        sslCtx = null;
    }
    EventLoopGroup group = new NioEventLoopGroup();
    try {
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {

            @Override
            protected void initChannel(SocketChannel ch) throws Exception {
                ChannelPipeline p = ch.pipeline();
                if (sslCtx != null) {
                    p.addLast(sslCtx.newHandler(ch.alloc(), HOST, PORT));
                }
                p.addLast(new BinaryMemcacheClientCodec());
                p.addLast(new BinaryMemcacheObjectAggregator(Integer.MAX_VALUE));
                p.addLast(new MemcacheClientHandler());
            }
        });
        // Start the connection attempt.
        Channel ch = b.connect(HOST, PORT).sync().channel();
        // Read commands from the stdin.
        System.out.println("Enter commands (quit to end)");
        System.out.println("get <key>");
        System.out.println("set <key> <value>");
        ChannelFuture lastWriteFuture = null;
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        for (; ; ) {
            String line = in.readLine();
            if (line == null) {
                break;
            }
            if ("quit".equals(line.toLowerCase())) {
                ch.close().sync();
                break;
            }
            // Sends the received line to the server.
            lastWriteFuture = ch.writeAndFlush(line);
        }
        // Wait until all messages are flushed before closing the channel.
        if (lastWriteFuture != null) {
            lastWriteFuture.sync();
        }
    } finally {
        group.shutdownGracefully();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) InputStreamReader(java.io.InputStreamReader) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Channel(io.netty.channel.Channel) SocketChannel(io.netty.channel.socket.SocketChannel) BinaryMemcacheClientCodec(io.netty.handler.codec.memcache.binary.BinaryMemcacheClientCodec) ChannelPipeline(io.netty.channel.ChannelPipeline) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) BufferedReader(java.io.BufferedReader) Bootstrap(io.netty.bootstrap.Bootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) SslContext(io.netty.handler.ssl.SslContext) BinaryMemcacheObjectAggregator(io.netty.handler.codec.memcache.binary.BinaryMemcacheObjectAggregator)

Example 15 with ChannelPipeline

use of io.netty.channel.ChannelPipeline in project netty by netty.

the class ObjectEchoServer method main.

public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
    } else {
        sslCtx = null;
    }
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {

            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ChannelPipeline p = ch.pipeline();
                if (sslCtx != null) {
                    p.addLast(sslCtx.newHandler(ch.alloc()));
                }
                p.addLast(new ObjectEncoder(), new ObjectDecoder(ClassResolvers.cacheDisabled(null)), new ObjectEchoServerHandler());
            }
        });
        // Bind and start to accept incoming connections.
        b.bind(PORT).sync().channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
Also used : NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) LoggingHandler(io.netty.handler.logging.LoggingHandler) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) ObjectDecoder(io.netty.handler.codec.serialization.ObjectDecoder) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ObjectEncoder(io.netty.handler.codec.serialization.ObjectEncoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) SslContext(io.netty.handler.ssl.SslContext)

Aggregations

ChannelPipeline (io.netty.channel.ChannelPipeline)145 Channel (io.netty.channel.Channel)36 SocketChannel (io.netty.channel.socket.SocketChannel)36 Bootstrap (io.netty.bootstrap.Bootstrap)33 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)33 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)32 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)32 ChannelFuture (io.netty.channel.ChannelFuture)29 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)25 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)25 EventLoopGroup (io.netty.channel.EventLoopGroup)22 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)22 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)17 InetSocketAddress (java.net.InetSocketAddress)17 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)16 SslHandler (io.netty.handler.ssl.SslHandler)16 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)14 LoggingHandler (io.netty.handler.logging.LoggingHandler)14 IOException (java.io.IOException)14 ChannelHandler (io.netty.channel.ChannelHandler)13