是否使用HttpClientUpgradeHandler建立Websocketconnection?

是否使用HttpClientUpgradeHandler建立Websocketconnection?,websocket,netty,handshake,Websocket,Netty,Handshake,我尝试建立websocketconnection。但我的websocketcontent一直因为不可读而被拒绝。现在,我使用以下处理程序堆栈建立连接: p.addLast(ClientSslHandler), p.addLast(new HttpClientCodec()), p.addLast(new HttpObjectAggregator(8192)), p.addLast(new WebSocketClientProtocolHandler(...)), p.addlast(new my

我尝试建立websocketconnection。但我的websocketcontent一直因为不可读而被拒绝。现在,我使用以下处理程序堆栈建立连接:

p.addLast(ClientSslHandler),
p.addLast(new HttpClientCodec()),
p.addLast(new HttpObjectAggregator(8192)),
p.addLast(new WebSocketClientProtocolHandler(...)),
p.addlast(new myHandler);
问题是(我认为)HttpClientCodec一直将我的Websocketframes编码为Httpframes。 这就是为什么我认为我可以使用HttpClientUpgradeHandler来处理握手,然后改为纯Websocketconnection。这是一个可行的解决方案吗?或者还有其他解决办法吗

编辑:将WebSocketClientProtocolHandler更改为HttpClientUpgradeHandler

编辑2: 公共类ShipSocketClient{ 静态最终字符串URL=System.getProperty(“URL”wss://10.2.3.44:4712”

这是传出包的外观:

         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 88 1d 11 30 53 54 41 54 45 5f 57 41 49 54 5f 43 |...0STATE_WAIT_C|
|00000010| 4c 4f 53 45 5f 43 4f 4e 4e 45 43 54 49 4f 4e    |LOSE_CONNECTION |
+--------+-------------------------------------------------+----------------+
         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 82 9d 12 1e 8c 5a 12 1f f7 78 71 71 e2 34 77 7d |.....Z...xqq.4w}|
|00000010| f8 33 7d 70 c4 3f 7e 72 e3 78 28 3c fe 3f 73 7a |.3}p.?~r.x(<.?sz|
|00000020| f5 78 6f                                        |.xo             |
+--------+-------------------------------------------------+----------------+
+-------------------------------------------------+
|01 2 3 4 5 6 7 8 9 a b c d e f|
+--------+-------------------------------------------------+----------------+
|00000000 | 82 9d 12 1e 8c 5a 12 1f f7 78 71 e2 34 77 7d |…Z…xqq.4w}|

|00000010 | f8 33 7d 70 c4 3f 7e 72 e3 78 28 3c fe 3f 73 7a |.3}p.?~r.x(如果您想升级到WebSockets,您应该使用
WebSocketClientHandshaker

Netty本身就有一个例子:


谢谢你的回答。也许我没有把问题说清楚。但通过我的代码,我可以升级到WebSocket。不幸的是,HttpClientCodec一直在编码我的WebSocket框架(我想)。这就是我想使用HttpClientUpgradeHandler的原因。但我不确定这是否是一个合适的解决方案,因为我找不到其他这样做的人。我需要为WebsocketClientProtocolHandler实现HttpClientUpgradeHandler.UpgradeCodec。
         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 82 9d 12 1e 8c 5a 12 1f f7 78 71 71 e2 34 77 7d |.....Z...xqq.4w}|
|00000010| f8 33 7d 70 c4 3f 7e 72 e3 78 28 3c fe 3f 73 7a |.3}p.?~r.x(<.?sz|
|00000020| f5 78 6f                                        |.xo             |
+--------+-------------------------------------------------+----------------+