【问题标题】:WebSocket compression in nettynetty中的WebSocket压缩
【发布时间】:2015-11-18 03:47:50
【问题描述】:

在来自 netty 存储库的 WebSocket-Server example 中,WebSocket-Server 像这样初始化

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerHandler());
}

但是 WebSocketServerCompressionHandler 没有随 netty-all 包一起提供。这是一个过时的例子还是我错过了另一个包。

【问题讨论】:

    标签: java websocket server netty


    【解决方案1】:

    您使用的是哪个版本的 Netty?您链接到的示例适用于 Netty 5.0。

    WebSocketServerCompressionHandler 在 Netty 5.0 的 netty-codec-http 包中,应该包含在 netty-all 中。

    如果您使用的是 Netty 4.0 或 Netty 4.1,请尝试以下示例 - https://github.com/netty/netty/blob/4.0/example/src/main/java/io/netty/example/http/websocketx/server/WebSocketServerInitializer.java

    【讨论】:

    最近更新 更多