当前位置: 首页>>代码示例>>Java>>正文


Java LengthFieldPrepender类代码示例

本文整理汇总了Java中io.netty.handler.codec.LengthFieldPrepender的典型用法代码示例。如果您正苦于以下问题:Java LengthFieldPrepender类的具体用法?Java LengthFieldPrepender怎么用?Java LengthFieldPrepender使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LengthFieldPrepender类属于io.netty.handler.codec包,在下文中一共展示了LengthFieldPrepender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import io.netty.handler.codec.LengthFieldPrepender; //导入依赖的package包/类
public void run() {
	workerGroup = new NioEventLoopGroup();
	try {
		Bootstrap b = new Bootstrap();
		b.group(workerGroup);
		b.channel(NioSocketChannel.class);
		// b.option(ChannelOption.SO_KEEPALIVE, true);
		b.handler(new ChannelInitializer<SocketChannel>() {
			@Override
			public void initChannel(SocketChannel ch) throws Exception {
				ChannelPipeline pipeline = ch.pipeline();
				pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(65536, 0, 4, 0, 4));
				pipeline.addLast("frameEncoder", new LengthFieldPrepender(4));
				pipeline.addLast("decoder", new MsgPackDecode());
				pipeline.addLast("encoder", new MsgPackEncode());
				pipeline.addLast(new ClientHandler());
			}
		});
		channel = b.connect(clientProperties.getServerHost(), clientProperties.getServerPort()).sync().channel();
		status = Status.START;
		channel.closeFuture().sync();
	} catch (Exception e) {
		e.printStackTrace();
	}
	status = Status.STOP;
}
 
开发者ID:ctodb,项目名称:push,代码行数:27,代码来源:Client.java

示例2: initChannel

import io.netty.handler.codec.LengthFieldPrepender; //导入依赖的package包/类
@Override
protected void initChannel(Channel ch) throws Exception {
    ChannelPipeline pip = ch.pipeline();
    int maxLength = 1048576;
    int lengthFieldLength = 4;
    int ignoreLength = -4;
    int offset = 0;
    pip.addLast(new LengthFieldBasedFrameDecoder(maxLength, offset, lengthFieldLength, ignoreLength, lengthFieldLength));
    pip.addLast(new MessageDecoder(builder.getImessageandhandler()));
    pip.addLast(new LengthFieldPrepender(4, true));
    pip.addLast(new MessageEncoder(builder.getImessageandhandler()));
    pip.addLast(new MessageExecutor(builder.getConsumer(), builder.getListener()));
    for (ChannelHandler handler : builder.getExtraHandlers()) {
        pip.addLast(handler);
    }
}
 
开发者ID:beimi,项目名称:ServerCore,代码行数:17,代码来源:NetworkServiceImpl.java

示例3: service

import io.netty.handler.codec.LengthFieldPrepender; //导入依赖的package包/类
public static void service() throws Exception {
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.group(bossGroup, workerGroup);
    bootstrap.channel(NioServerSocketChannel.class);
    bootstrap.childHandler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();
            pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
            pipeline.addLast(new LengthFieldPrepender(4));
            pipeline.addLast(new StringDecoder(CharsetUtil.UTF_8));
            pipeline.addLast(new StringEncoder(CharsetUtil.UTF_8));
            pipeline.addLast(new TcpServerHandler());
        }

    });
    ChannelFuture f = bootstrap.bind(IP, PORT).sync();
    f.channel().closeFuture().sync();
    System.out.println("TCP服务器已启动");
}
 
开发者ID:generallycloud,项目名称:baseio,代码行数:22,代码来源:MyNettyServer.java

示例4: getBootstrap

import io.netty.handler.codec.LengthFieldPrepender; //导入依赖的package包/类
/**
 * 初始化Bootstrap
 * @return
 */
public static final Bootstrap getBootstrap(){
	EventLoopGroup group = new NioEventLoopGroup();
	Bootstrap b = new Bootstrap();
	b.group(group).channel(NioSocketChannel.class);
	b.handler(new ChannelInitializer<Channel>() {
		@Override
		protected void initChannel(Channel ch) throws Exception {
			ChannelPipeline pipeline = ch.pipeline();
			pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
			pipeline.addLast("frameEncoder", new LengthFieldPrepender(4));
			pipeline.addLast("decoder", new StringDecoder(CharsetUtil.UTF_8));
			pipeline.addLast("encoder", new StringEncoder(CharsetUtil.UTF_8));
			pipeline.addLast("handler", new TcpClientHandler());
		}
	});
	b.option(ChannelOption.SO_KEEPALIVE, true);
	return b;
}
 
开发者ID:zhu410289616,项目名称:RHSocketServerDemo-Netty,代码行数:23,代码来源:TcpClient.java

示例5: run

import io.netty.handler.codec.LengthFieldPrepender; //导入依赖的package包/类
protected static void run() throws Exception {
	ServerBootstrap b = new ServerBootstrap();
	b.group(bossGroup, workerGroup);
	b.channel(NioServerSocketChannel.class);
	b.childHandler(new ChannelInitializer<SocketChannel>() {
		@Override
		public void initChannel(SocketChannel ch) throws Exception {
			ChannelPipeline pipeline = ch.pipeline();
			pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
			pipeline.addLast("frameEncoder", new LengthFieldPrepender(4));
			pipeline.addLast("decoder", new StringDecoder(CharsetUtil.UTF_8));
			pipeline.addLast("encoder", new StringEncoder(CharsetUtil.UTF_8));
			pipeline.addLast(new TcpServerHandler());
		}
	});

	b.bind(IP, PORT).sync();
	System.out.println("TCP服务器已启动");
}
 
开发者ID:zhu410289616,项目名称:RHSocketServerDemo-Netty,代码行数:20,代码来源:TcpServer.java

示例6: provideHandlerProviders

import io.netty.handler.codec.LengthFieldPrepender; //导入依赖的package包/类
@Provides
@EppProtocol
static ImmutableList<Provider<? extends ChannelHandler>> provideHandlerProviders(
    Provider<SslServerInitializer<NioSocketChannel>> sslServerInitializerProvider,
    Provider<ProxyProtocolHandler> proxyProtocolHandlerProvider,
    @EppProtocol Provider<ReadTimeoutHandler> readTimeoutHandlerProvider,
    Provider<LengthFieldBasedFrameDecoder> lengthFieldBasedFrameDecoderProvider,
    Provider<LengthFieldPrepender> lengthFieldPrependerProvider,
    Provider<EppServiceHandler> eppServiceHandlerProvider,
    Provider<LoggingHandler> loggingHandlerProvider,
    Provider<FullHttpRequestRelayHandler> relayHandlerProvider) {
  return ImmutableList.of(
      proxyProtocolHandlerProvider,
      sslServerInitializerProvider,
      readTimeoutHandlerProvider,
      lengthFieldBasedFrameDecoderProvider,
      lengthFieldPrependerProvider,
      eppServiceHandlerProvider,
      loggingHandlerProvider,
      relayHandlerProvider);
}
 
开发者ID:google,项目名称:nomulus,代码行数:22,代码来源:EppProtocolModule.java

示例7: testPrependLengthInLittleEndian

import io.netty.handler.codec.LengthFieldPrepender; //导入依赖的package包/类
@Test
public void testPrependLengthInLittleEndian() throws Exception {
    final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(ByteOrder.LITTLE_ENDIAN, 4, 0, false));
    ch.writeOutbound(msg);
    ByteBuf buf = (ByteBuf) ch.readOutbound();
    assertEquals(5, buf.readableBytes());
    byte[] writtenBytes = new byte[buf.readableBytes()];
    buf.getBytes(0, writtenBytes);
    assertEquals(1, writtenBytes[0]);
    assertEquals(0, writtenBytes[1]);
    assertEquals(0, writtenBytes[2]);
    assertEquals(0, writtenBytes[3]);
    assertEquals('A', writtenBytes[4]);
    buf.release();
    assertFalse("The channel must have been completely read", ch.finish());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:17,代码来源:LengthFieldPrependerTest.java

示例8: connect

import io.netty.handler.codec.LengthFieldPrepender; //导入依赖的package包/类
public void connect() throws Exception {
    workerGroup = new NioEventLoopGroup();

    Bootstrap bootstrap =
            new Bootstrap()
                    .group(workerGroup)
                    .channel(NioSocketChannel.class)
                    .handler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        public void initChannel(SocketChannel socketChannel) throws Exception {
                            ChannelPipeline pipeline = socketChannel.pipeline();

                            pipeline.addLast(new LengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4));
                            pipeline.addLast(new ProtobufDecoder(Protocol.BaseMessage.getDefaultInstance()));

                            clientHandler = new ClientHandler();
                            pipeline.addLast(clientHandler);

                            pipeline.addLast(new LengthFieldPrepender(4));
                            pipeline.addLast(new ProtobufEncoder());
                        }
                    });

    ChannelFuture channelFuture = bootstrap.connect(host, port).sync();
    channel = channelFuture.channel();
}
 
开发者ID:nhekfqn,项目名称:netty-protobuf-server-seed,代码行数:27,代码来源:Client.java

示例9: initChannel

import io.netty.handler.codec.LengthFieldPrepender; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
  LOGGER.info("Setting up Server channel !!");
  ch.pipeline().addLast("decoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
  ch.pipeline().addLast("encoder", new LengthFieldPrepender(4));
  //ch.pipeline().addLast("logger", new LoggingHandler());
  // Create server metric for this handler and add to aggregate if present
  NettyServerMetrics serverMetric =
      new NettyServerMetrics(_registry, NettyTCPServer.class.getName() + "_" + Utils.getUniqueId() + "_");

  if (null != _globalMetrics) {
    _globalMetrics.addTransportClientMetrics(serverMetric);
  }

  ch.pipeline().addLast("request_handler",
      new NettyChannelInboundHandler(_handlerFactory.createNewRequestHandler(), serverMetric, _defaultLargeQueryLatencyMs));
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:18,代码来源:NettyTCPServer.java

示例10: initChannel

import io.netty.handler.codec.LengthFieldPrepender; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {

    if (sslContext != null) {
        ch.pipeline().addLast(sslContext.newHandler(ch.alloc(), host, port));
    }

    // In
    ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
    if (cryptoFunction != null) {
        ch.pipeline().addLast(cryptoFunction.getDecoder());
    }
    ch.pipeline().addLast(new PacketDecoder(protocol));

    // Out
    ch.pipeline().addLast(new LengthFieldPrepender(4));
    if (cryptoFunction != null) {
        ch.pipeline().addLast(cryptoFunction.getEncoder());
    }
    ch.pipeline().addLast(new PacketEncoder(protocol));

    // Handler
    ch.pipeline().addLast(new CascadeSession(ch, protocol, sessionListener));
}
 
开发者ID:JackWhite20,项目名称:Cascade,代码行数:25,代码来源:CascadeChannelInitializer.java

示例11: initChannel

import io.netty.handler.codec.LengthFieldPrepender; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();
    // Enable TCPS if necessary.
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }
    p.addLast("logger", new LoggingHandler(LogLevel.DEBUG));

    p.addLast(new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, Integer.MAX_VALUE, 0, 4, 0, 4, true));
    p.addLast(new ByteBufferDecoder());

    p.addLast(new LengthFieldPrepender(4, 0, false) {
        @Override
        protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
            ByteBuf outWithLittleEndian = out.order(ByteOrder.LITTLE_ENDIAN);
            super.encode(ctx, msg, outWithLittleEndian);
        }
    });
    p.addLast(new ByteBufferEncoder());
    p.addLast(handler);
}
 
开发者ID:FIWARE-Middleware,项目名称:KIARA,代码行数:23,代码来源:TcpClientInitializer.java

示例12: initChannel

import io.netty.handler.codec.LengthFieldPrepender; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();
    // Enable TCPS if necessary.
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }
    p.addLast("logger", new LoggingHandler(LogLevel.DEBUG));

    p.addLast(new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, Integer.MAX_VALUE, 0, 4, 0, 4, true));
    p.addLast(new ByteBufferDecoder());

    p.addLast(new LengthFieldPrepender(4, 0, false) {
        @Override
        protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
            ByteBuf outWithLittleEndian = out.order(ByteOrder.LITTLE_ENDIAN);
            super.encode(ctx, msg, outWithLittleEndian);
        }
    });
    p.addLast(new ByteBufferEncoder());
    p.addLast(new TcpHandler(transportFactory, path, connectionListener));
}
 
开发者ID:FIWARE-Middleware,项目名称:KIARA,代码行数:23,代码来源:TcpServerInitializer.java

示例13: initChannel

import io.netty.handler.codec.LengthFieldPrepender; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    // Add SSL handler first to encrypt and decrypt everything.
    // In this example, we use a bogus certificate in the server side
    // and accept any invalid certificates in the client side.
    // You will need something more complicated to identify both
    // and server in the real world.

    SSLEngine engine =
        SecureSocketSslContextFactory.getClientContext().createSSLEngine();
    engine.setUseClientMode(true);

    pipeline.addLast("ssl", new SslHandler(engine));
    // On top of the SSL handler, add the text line codec.
    // pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
    pipeline.addLast("length-decoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
    pipeline.addLast("String-decoder", new StringDecoder());  
    pipeline.addLast("length-encoder", new LengthFieldPrepender(4));
    pipeline.addLast("String-encoder", new StringEncoder()); 
    pipeline.addLast("handler", new SecureSocketClientHandler());
}
 
开发者ID:devsunny,项目名称:netty-ssl-example,代码行数:24,代码来源:SecureSocketClientInitializer.java

示例14: run

import io.netty.handler.codec.LengthFieldPrepender; //导入依赖的package包/类
public void run() throws InterruptedException {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();

    try {
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(bossGroup, workerGroup)
                .localAddress(port)
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new LengthFieldPrepender(4)).addLast(new LengthFieldServerHandler());
                    }
                });

        ChannelFuture cf = bootstrap.bind().sync();
        cf.channel().closeFuture().sync();
    } finally {
        workerGroup.shutdownGracefully();
        bossGroup.shutdownGracefully();
    }
}
 
开发者ID:edgar615,项目名称:javase-study,代码行数:24,代码来源:LengthFieldServer.java

示例15: run

import io.netty.handler.codec.LengthFieldPrepender; //导入依赖的package包/类
public void run(String host, int port) throws Exception {

        EventLoopGroup group = new NioEventLoopGroup();
        try {
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(group)
                    .channel(NioSocketChannel.class)
                    .handler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        protected void initChannel(SocketChannel ch) throws Exception {
                            ch.pipeline().addLast(new LoggingHandler(LogLevel.DEBUG))
                                    .addLast(new LengthFieldPrepender(4))
                                    .addLast(new StringEncoder())
                                    .addLast(new ObjectToJsonStringEncoder())
                                    .addLast(new ObjectEchoClientHandler());
                        }
                    });

            bootstrap.connect(host, port).sync().channel().closeFuture().sync();
        } finally {
            group.shutdownGracefully();
        }
    }
 
开发者ID:edgar615,项目名称:javase-study,代码行数:24,代码来源:ObjectEchoClient.java


注:本文中的io.netty.handler.codec.LengthFieldPrepender类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。