Skip to content
Advertisement

netty-incubator-codec-quic: How to get remoteAddress?

I need to know the remote address at the server side. I tried bellow ways and failed:

  1. QuicStreamChannel.remoteAddress() returns QuicStreamAddress, which cannot be casted to InetSocketAddress. QuicStreamAddress or QuicConnectionAddress does not contain remote IP address or port at all.
  2. class io.netty.buffer.PooledUnsafeDirectByteBuf cannot be cast to class io.netty.channel.socket.DatagramPacket so I cannot use DatagramPacket.sender() to get the sender address.
  3. (QuicChannel) (ctx.channel().parent())).sslEngine().getPeerHost() — this returns null.

Advertisement

Answer

You want to intercept QuicConnectionEvents. 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());
        }
    }
};
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement