I need to know the remote address at the server side. I tried bellow ways and failed:
QuicStreamChannel.remoteAddress()
returnsQuicStreamAddress
, which cannot be casted toInetSocketAddress
.QuicStreamAddress
orQuicConnectionAddress
does not contain remote IP address or port at all.- class
io.netty.buffer.PooledUnsafeDirectByteBuf
cannot be cast to classio.netty.channel.socket.DatagramPacket
so I cannot useDatagramPacket.sender()
to get the sender address. (QuicChannel) (ctx.channel().parent())).sslEngine().getPeerHost()
— this returns null.
Advertisement
Answer
You want to intercept QuicConnectionEvent
s. These events contain the address. Be aware that the address can change (in this case a new event is fired).
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()); } } };