diff --git a/src/main/java/reactor/ipc/netty/NettyContext.java b/src/main/java/reactor/ipc/netty/NettyContext.java index 7699381d0e..12ee4266f8 100644 --- a/src/main/java/reactor/ipc/netty/NettyContext.java +++ b/src/main/java/reactor/ipc/netty/NettyContext.java @@ -20,6 +20,7 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelOutboundHandler; +import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.ServerSocketChannel; import io.netty.channel.socket.SocketChannel; import reactor.core.Disposable; @@ -185,6 +186,10 @@ default InetSocketAddress address(){ if (c instanceof ServerSocketChannel) { return ((ServerSocketChannel) c).localAddress(); } + if (c instanceof DatagramChannel) { + InetSocketAddress a = ((DatagramChannel) c).remoteAddress(); + return a != null ? a : ((DatagramChannel)c ).localAddress(); + } throw new IllegalStateException("Does not have an InetSocketAddress"); } diff --git a/src/main/java/reactor/ipc/netty/channel/ChannelOperations.java b/src/main/java/reactor/ipc/netty/channel/ChannelOperations.java index 806e186967..9f169241e1 100644 --- a/src/main/java/reactor/ipc/netty/channel/ChannelOperations.java +++ b/src/main/java/reactor/ipc/netty/channel/ChannelOperations.java @@ -165,7 +165,8 @@ public InetSocketAddress address() { return ((SocketChannel) c).remoteAddress(); } if (c instanceof DatagramChannel) { - return ((DatagramChannel) c).localAddress(); + InetSocketAddress a = ((DatagramChannel) c).remoteAddress(); + return a != null ? a : ((DatagramChannel)c ).localAddress(); } throw new IllegalStateException("Does not have an InetSocketAddress"); } @@ -501,4 +502,4 @@ public interface OnNew { Subscription.class, "outboundSubscription"); -} \ No newline at end of file +} diff --git a/src/main/java/reactor/ipc/netty/channel/ServerContextHandler.java b/src/main/java/reactor/ipc/netty/channel/ServerContextHandler.java index d3975deb75..817b378cd8 100644 --- a/src/main/java/reactor/ipc/netty/channel/ServerContextHandler.java +++ b/src/main/java/reactor/ipc/netty/channel/ServerContextHandler.java @@ -72,17 +72,7 @@ else if (log.isErrorEnabled()) { @Override public InetSocketAddress address() { - Channel c = f.channel(); - if (c instanceof SocketChannel) { - return ((SocketChannel) c).remoteAddress(); - } - if (c instanceof ServerSocketChannel) { - return ((ServerSocketChannel) c).localAddress(); - } - if (c instanceof DatagramChannel) { - return ((DatagramChannel) c).localAddress(); - } - throw new IllegalStateException("Does not have an InetSocketAddress"); + return ((ServerSocketChannel) f.channel()).localAddress(); } @Override