當前位置: 首頁>>代碼示例>>Java>>正文


Java StringDecoder類代碼示例

本文整理匯總了Java中io.netty.handler.codec.string.StringDecoder的典型用法代碼示例。如果您正苦於以下問題:Java StringDecoder類的具體用法?Java StringDecoder怎麽用?Java StringDecoder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StringDecoder類屬於io.netty.handler.codec.string包,在下文中一共展示了StringDecoder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: switchToBinary

import io.netty.handler.codec.string.StringDecoder; //導入依賴的package包/類
private void switchToBinary(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();
    p.addLast(new DelimiterBasedFrameDecoder(maxFrameLength, Delimiters.lineDelimiter()));
    p.addLast(new StringDecoder(Charset.forName(charset)));
    p.addLast(new NetoJsonToMessageDecoder(opcodeMap));

    NetoMessageToJsonEncoder netoMessageToJsonEncoder = new NetoMessageToJsonEncoder();
    netoMessageToJsonEncoder.setOpcodeMap(opcodeMap);

    p.addLast(netoMessageToJsonEncoder);
    p.addLast(new MessageHandler(redisService));
    p.remove(this);


    // 핸들러를 다시 등록 했으므로 이벤트를 전파
    ctx.fireChannelActive();
}
 
開發者ID:veritasware,項目名稱:neto,代碼行數:18,代碼來源:ProtocolUnificationHandler.java

示例2: initChannel

import io.netty.handler.codec.string.StringDecoder; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {

    NetoJsonToMessageDecoder decoder = new NetoJsonToMessageDecoder(opcodeMap);
    NetoMessageToJsonEncoder encoder = new NetoMessageToJsonEncoder();

    if (opcodeMap instanceof BiMap) {
        encoder.setOpcodeMap((BiMap<Integer, Class<? extends NetoJsonMessage>>) opcodeMap);
    }

    MessageHandler handler = new MessageHandler(redisService);

    ChannelPipeline p = ch.pipeline();

    p.addLast(new DelimiterBasedFrameDecoder(maxFrameLength, Delimiters.lineDelimiter()));
    p.addLast(new StringDecoder(Charset.forName(charset)));
    p.addLast(decoder);
    p.addLast(encoder);
    p.addLast(handler);
}
 
開發者ID:veritasware,項目名稱:neto,代碼行數:21,代碼來源:ChannelServerInitializer.java

示例3: initChannel

import io.netty.handler.codec.string.StringDecoder; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast(new LoggingHandler());
    // 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.
    if (sslCtx != null)
        pipeline.addLast(sslCtx.newHandler(ch.alloc(), SecureChatClient.HOST, SecureChatClient.PORT));

    // On top of the SSL handler, add the text line codec.
    pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
    pipeline.addLast(new StringDecoder());
    pipeline.addLast(new StringEncoder());

    // and then business logic.
    pipeline.addLast(new SecureChatClientHandler());
}
 
開發者ID:veritasware,項目名稱:neto,代碼行數:22,代碼來源:SecureChatClientInitializer.java

示例4: serverBootStrapWithOptionsTest

import io.netty.handler.codec.string.StringDecoder; //導入依賴的package包/類
@Test
public void serverBootStrapWithOptionsTest() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
	LinkedHashMap<String, Object> channelHandlerOptions = new LinkedHashMap<String, Object>();
	
	channelHandlerOptions.put("lineFrame", new LineBasedFrameDecoder(2000));
	channelHandlerOptions.put("decoder", new StringDecoder());
	channelHandlerOptions.put("encoder", new StringEncoder());
	channelHandlerOptions.put("handler", new ChannelInboundHandlerAdapter() {
		
		@Override
		public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
			log.info("Message Received and forward to ConsumerProcessor. Msg -> {}", msg);
		}
	});
	
	Server server = BootStrap.builder()
			.port(5252)
			.options(channelHandlerOptions)
			.messageConsumer(msg -> log.info(msg))
			.build();
	
	assertNotNull(server);
}
 
開發者ID:Creativesource-Sys,項目名稱:jfast,代碼行數:24,代碼來源:ServerTest.java

示例5: EchoClient

import io.netty.handler.codec.string.StringDecoder; //導入依賴的package包/類
public EchoClient(String host, int port) {
    EventLoopGroup worker = new NioEventLoopGroup();

    Bootstrap b = new Bootstrap();

    b.group(worker)
            .channel(NioSocketChannel.class)
            .option(ChannelOption.SO_KEEPALIVE, true)
            .handler(new ChannelInitializer<SocketChannel>() {
                @Override
                protected void initChannel(SocketChannel socketChannel) {
                    socketChannel.pipeline()
                            .addLast(new StringDecoder())
                            .addLast(new StringEncoder())
                            .addLast(ech);
                }
            });

    b.connect(host, port);
}
 
開發者ID:AlphaHelixDev,項目名稱:AlphaLibary,代碼行數:21,代碼來源:EchoClient.java

示例6: connect

import io.netty.handler.codec.string.StringDecoder; //導入依賴的package包/類
public void connect(int port, String host) throws InterruptedException {
	
	EventLoopGroup group = new NioEventLoopGroup();
	try{
		Bootstrap b = new Bootstrap();
		b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true)
		.handler(new ChannelInitializer<SocketChannel>() {

			@Override
			protected void initChannel(SocketChannel ch) throws Exception {
				ch.pipeline().addLast(new LineBasedFrameDecoder(1024));
				ch.pipeline().addLast(new StringDecoder());
				ch.pipeline().addLast(new TimeClientHandler());
			}
			
		});
		
		//發送異步鏈接操作
		ChannelFuture f = b.connect(host, port).sync();
		//等待客戶端鏈路關閉
		f.channel().closeFuture().sync();
	}finally{
		group.shutdownGracefully();
	}
	
}
 
開發者ID:hdcuican,項目名稱:java_learn,代碼行數:27,代碼來源:TimeClient.java

示例7: initChannel

import io.netty.handler.codec.string.StringDecoder; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
	ch.config().setAllowHalfClosure(true);
	ChannelPipeline pipeline = ch.pipeline();

	//IdleStateHandler 與客戶端鏈接後,根據超出配置的時間自動觸發userEventTriggered
	//readerIdleTime服務端長時間沒有讀到數據,則為讀空閑,觸發讀空閑監聽,並自動關閉鏈路連接,周期性按readerIdleTime的超時間觸發空閑監聽方法
	//writerIdleTime服務端長時間沒有發送寫請求,則為空閑,觸發寫空閑監聽,空閑期間,周期性按writerIdleTime的超時間觸發空閑監聽方法
	//allIdleTime 服務端在allIdleTime時間內未接收到客戶端消息,或者,也未去向客戶端發送消息,則觸發周期性操作
	pipeline.addLast("ping", new IdleStateHandler(10, 20, 35, TimeUnit.SECONDS));
	// 以("\n")為結尾分割的 解碼器
	pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
	// 字符串解碼 和 編碼
	pipeline.addLast("decoder", new StringDecoder());
	pipeline.addLast("encoder", new StringEncoder());
	// 自己的邏輯Handler
	pipeline.addLast("handler", new DataServerHandler(nodeInfo));
}
 
開發者ID:beijing-penguin,項目名稱:raft-java,代碼行數:19,代碼來源:StartServer.java

示例8: connect

import io.netty.handler.codec.string.StringDecoder; //導入依賴的package包/類
public void connect(String host, int port) throws InterruptedException {
    EventLoopGroup group = new NioEventLoopGroup();
    try {
        Bootstrap b = new Bootstrap();
        b.group(group)
                .channel(NioSocketChannel.class)
                .option(ChannelOption.TCP_NODELAY, true)
                .handler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel ch) throws Exception {

                        ch.pipeline().addLast(new FixedLengthFrameDecoder(1<<5));
                        ch.pipeline().addLast(new StringDecoder());
                        ch.pipeline().addLast(new StringEncoder());

                        ch.pipeline().addLast(new ClientHandler());
                    }
                });

        ChannelFuture future = b.connect(host, port).sync();

        future.channel().closeFuture().sync();
    } finally {
        group.shutdownGracefully();
    }
}
 
開發者ID:TFdream,項目名稱:netty-tutorials,代碼行數:27,代碼來源:NettyClient.java

示例9: initChannel

import io.netty.handler.codec.string.StringDecoder; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
    ChannelPipeline pipeline = socketChannel.pipeline();
    pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()))
            .addLast("decoder", new StringDecoder())
            .addLast("encoder", new StringEncoder())
            .addLast("json_to_ob",new JsonToObjectHandler())
            .addLast("register",new RegisterHandler())
            .addLast("authority", new AuthorityHandler())
            .addLast("enterGroup",new EnterGroupHandler())
            .addLast("channelManager", new ChannelManagerHandler())
            .addLast("createGroup", new CreateGroupHandler())
            .addLast("addGroup", new AddGroupHandler())
            .addLast("deleteGroup",new DeleteGroupHandler())
            .addLast("Limiter", new LimiterHandler())
            .addLast("log", new LoggerHandler())
            .addLast("response", new Responser());
}
 
開發者ID:tztztztztz,項目名稱:bookish-meme,代碼行數:19,代碼來源:ChatServerInitializer.java

示例10: initChannel

import io.netty.handler.codec.string.StringDecoder; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    /*
     * 這個地方的 必須和服務端對應上。否則無法正常解碼和編碼
     * 
     * 解碼和編碼 我將會在下一張為大家詳細的講解。再次暫時不做詳細的描述
     */
    pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192,
            Delimiters.lineDelimiter()));
    pipeline.addLast("decoder", new StringDecoder());
    pipeline.addLast("encoder", new StringEncoder());

    // 客戶端的邏輯
    pipeline.addLast("handler", new HelloClientHandler());
}
 
開發者ID:cowthan,項目名稱:JavaAyo,代碼行數:18,代碼來源:HelloClientInitializer.java

示例11: initChannel

import io.netty.handler.codec.string.StringDecoder; //導入依賴的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.
    pipeline.addLast(sslCtx.newHandler(ch.alloc()));

    // On top of the SSL handler, add the text line codec.
    pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
    pipeline.addLast(new StringDecoder());
    pipeline.addLast(new StringEncoder());

    // and then business logic.
    pipeline.addLast(new SecureChatServerHandler());
}
 
開發者ID:cowthan,項目名稱:JavaAyo,代碼行數:20,代碼來源:SecureChatServerInitializer.java

示例12: initChannel

import io.netty.handler.codec.string.StringDecoder; //導入依賴的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.
    pipeline.addLast(sslCtx.newHandler(ch.alloc(), SecureChatClient.HOST, SecureChatClient.PORT));

    // On top of the SSL handler, add the text line codec.
    pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
    pipeline.addLast(new StringDecoder());
    pipeline.addLast(new StringEncoder());

    // and then business logic.
    pipeline.addLast(new SecureChatClientHandler());
}
 
開發者ID:cowthan,項目名稱:JavaAyo,代碼行數:20,代碼來源:SecureChatClientInitializer.java

示例13: main

import io.netty.handler.codec.string.StringDecoder; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    EventLoopGroup group = new OioEventLoopGroup();
    try {
        Bootstrap b = new Bootstrap();
        b.group(group)
         .channel(RxtxChannel.class)
         .handler(new ChannelInitializer<RxtxChannel>() {
             @Override
             public void initChannel(RxtxChannel ch) throws Exception {
                 ch.pipeline().addLast(
                     new LineBasedFrameDecoder(32768),
                     new StringEncoder(),
                     new StringDecoder(),
                     new RxtxClientHandler()
                 );
             }
         });

        ChannelFuture f = b.connect(new RxtxDeviceAddress(PORT)).sync();

        f.channel().closeFuture().sync();
    } finally {
        group.shutdownGracefully();
    }
}
 
開發者ID:cowthan,項目名稱:JavaAyo,代碼行數:26,代碼來源:RxtxClient.java

示例14: service

import io.netty.handler.codec.string.StringDecoder; //導入依賴的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

示例15: getBootstrap

import io.netty.handler.codec.string.StringDecoder; //導入依賴的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


注:本文中的io.netty.handler.codec.string.StringDecoder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。