gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:51:15 24 4
gpt4 key购买 nike

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

这是我的 channel 初始化

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);


}
});

异常(exception)是

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!

最佳答案

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

引用的重要部分:

Short story: WebSocketClientHandshaker reorganizes the Pipeline after receiving the upgrade from the server. If there is an HttpProxyHandler in the Pipeline, it has installed its own HttpClientCodec which gets wrecked by 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 或帖子引用的一种解决方法。

关于java - 使用保留操作码 7 的 CorruptedFrameException 数据帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42002457/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com