使用保留操作码7的CorruptedFrameException数据帧

时间:2017-02-02 12:35:22

标签: java websocket netty

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

这是我的频道init

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!

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,发现此问题是由于此处报告的WebSocket升级操作而出现的:WebSocket upgrade wrecks HttpProxyHandler。留下笔记,以防有人遇到同样的问题。

引用的重要部分:

  

短篇小说:WebSocketClientHandshaker之后重新组织了Pipeline   从服务器接收升级。如果有一个HttpProxyHandler   在Pipeline中,它已经安装了自己的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或post引用类型的解决方法。