繁体   English   中英

netty 4.0输入字节解码

[英]netty 4.0 input bytes decoding

我正在尝试实现一个非常简单的套接字服务器。 我需要阅读一些消息,用换行符或任何其他定界符分隔。

根据此文档: http : //netty.io/4.0/api/io/netty/handler/codec/string/StringDecoder.htmlhttp://netty.io/4.0/api/io/netty/handler/codec /DelimiterBasedFrameDecoder.html

此代码用于通道初始化程序

ChannelInitializer<SocketChannel> channelInitializer = new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) throws Exception {

                ch.pipeline().addLast("frameDecoder", new DelimiterBasedFrameDecoder(Delimiters.lineDelimiter()));
                ch.pipeline().addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8));

                // Encoder
                ch.pipeline().addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8));
            }
         };

应该可以。

但是没有适用于提供参数的解码器和编码器的合适构造函数。 他们期望一些整数作为第一个参数和一个Byte数组。 只有stringDecoder似乎还可以。

我在这里想念什么?

Netty 4.0的内联文档目前已过时-但处于alpha / beta /开发状态。

引入整数参数可防止缓冲区无限增长,并指定最大帧长度。

因此, new LineBasedFrameDecoder(4096))new DelimiterBasedFrameDecoder(Delimiters.lineDelimiter())类似。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM