【问题标题】:CorruptedFrameException data frame using reserved opcode 7使用保留操作码 7 的 CorruptedFrameException 数据帧
【发布时间】:2017-06-19 12:55:39
【问题描述】:

我正在尝试在我的公司代理后面建立 Web 套接字通信。我可以看到我的代理服务器和远程主机之间的代理连接已建立并得到握手响应。之后,当我尝试发送消息时,我得到了异常。

这是我的频道初始化

Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
            @Override
            protected void initChannel(SocketChannel ch) {
                ChannelPipeline p = ch.pipeline();

                if (sslCtx != null) {
                    p.addFirst("ssl", sslCtx.newHandler(ch.alloc(), host, port));
                }
                if(proxyHandler != null){
                    p.addFirst("proxyHandler", proxyHandler);

                }
                p.addLast(new LoggingHandler(LogLevel.DEBUG));
                p.addLast("clientCodec", new HttpClientCodec());

                p.addLast("decoder", new HttpRequestDecoder());
                p.addLast("aggregator", new HttpObjectAggregator(65536));
                p.addLast("encoder", new HttpResponseEncoder());
                p.addLast(handler);


            }
        });

例外是

io.netty.handler.codec.CorruptedFrameException: data frame using reserved opcode 7
  at io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder.protocolViolation(WebSocket08FrameDecoder.java:412)
  at io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder.decode(WebSocket08FrameDecoder.java:229)
  at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:411)
  at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:248)
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
  at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351)
  at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334)
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373)
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
  at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926)
  at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:129)
  at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:651)
  at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:574)
  at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:488)
  at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:450)
  at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873)
  at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
  at java.lang.Thread.run(Thread.java:745)
WebSocket Client
disconnected!

【问题讨论】:

    标签: java websocket netty


    【解决方案1】:

    我遇到了同样的问题,发现这个问题是 WebSocket 升级操作的结果,如下所示:WebSocket upgrade wrecks HttpProxyHandler。留个便条以防万一有人遇到同样的问题。

    引用的重要部分:

    短篇小说:WebSocketClientHandshaker 重组 Pipeline 后 从服务器接收升级。如果有 HttpProxyHandler 在管道中,它安装了自己的 HttpClientCodec 被 WebSocketClientHandshaker 破坏。

    HttpClientCodec#0        <-- #finishHandshake hit this one.
    ws-decoder               <-- We don't want this here.
    ws-encoder               <-- We don't want this here.
    Http11ProxyHandler#0
    SslHandler#0
    HttpClientCodec#1
                             <-- ws-xxcoder should appear here.
    DownendChannelHandler#0  <-- My own stuff.
    

    似乎还没有修复,所以可能需要破解 WebSocketClientHandshaker 或帖子引用的一种解决方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-10
      • 2018-05-14
      • 2021-09-08
      相关资源
      最近更新 更多