netty-incubator-codec-quic:如何获取远程地址?
netty-incubator-codec-quic: How to get remoteAddress?
我需要知道服务器端的远程地址。我尝试了以下方法但失败了:
QuicStreamChannel.remoteAddress()
returns QuicStreamAddress
,无法转换为 InetSocketAddress
。 QuicStreamAddress
或 QuicConnectionAddress
根本不包含远程 IP 地址或端口。
- class
io.netty.buffer.PooledUnsafeDirectByteBuf
无法转换为 class io.netty.channel.socket.DatagramPacket
所以我无法使用 DatagramPacket.sender()
获取发件人地址。
(QuicChannel) (ctx.channel().parent())).sslEngine().getPeerHost()
-- 这个 returns 空。
您想拦截 QuicConnectionEvent
s。这些事件包含地址。请注意地址可能会更改(在这种情况下会触发新事件)。
new ChannelInboundHandlerAdapter() {
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof QuicConnectionEvent) {
QuicConnectionEvent event = (QuicConnectionEvent) evt;
System.out.println(event.newAddress());
}
}
};
我需要知道服务器端的远程地址。我尝试了以下方法但失败了:
QuicStreamChannel.remoteAddress()
returnsQuicStreamAddress
,无法转换为InetSocketAddress
。QuicStreamAddress
或QuicConnectionAddress
根本不包含远程 IP 地址或端口。- class
io.netty.buffer.PooledUnsafeDirectByteBuf
无法转换为 classio.netty.channel.socket.DatagramPacket
所以我无法使用DatagramPacket.sender()
获取发件人地址。 (QuicChannel) (ctx.channel().parent())).sslEngine().getPeerHost()
-- 这个 returns 空。
您想拦截 QuicConnectionEvent
s。这些事件包含地址。请注意地址可能会更改(在这种情况下会触发新事件)。
new ChannelInboundHandlerAdapter() {
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof QuicConnectionEvent) {
QuicConnectionEvent event = (QuicConnectionEvent) evt;
System.out.println(event.newAddress());
}
}
};