diff --git a/src/main/java/io/vertx/mqtt/MqttClient.java b/src/main/java/io/vertx/mqtt/MqttClient.java index 7a75d6d6..18e11e58 100644 --- a/src/main/java/io/vertx/mqtt/MqttClient.java +++ b/src/main/java/io/vertx/mqtt/MqttClient.java @@ -19,10 +19,12 @@ import io.netty.handler.codec.mqtt.MqttQoS; import io.vertx.codegen.annotations.Fluent; import io.vertx.codegen.annotations.VertxGen; +import io.vertx.codegen.annotations.CacheReturn; import io.vertx.core.Future; import io.vertx.core.Handler; import io.vertx.core.Vertx; import io.vertx.core.buffer.Buffer; +import io.vertx.core.net.SocketAddress; import io.vertx.mqtt.impl.MqttClientImpl; import io.vertx.mqtt.messages.MqttAuthenticationExchangeMessage; import io.vertx.mqtt.messages.MqttConnAckMessage; @@ -268,4 +270,18 @@ static MqttClient create(Vertx vertx) { * @return if the connection between client and remote server is established/open */ boolean isConnected(); + + /** + * @return the remote address for this connection, possibly {@code null} (e.g a server bound on a domain socket). + * If {@code useProxyProtocol} is set to {@code true}, the address returned will be of the actual connecting client. + */ + @CacheReturn + SocketAddress remoteAddress(); + + /** + * @return the local address for this connection, possibly {@code null} (e.g a server bound on a domain socket) + * If {@code useProxyProtocol} is set to {@code true}, the address returned will be of the proxy. + */ + @CacheReturn + SocketAddress localAddress(); } diff --git a/src/main/java/io/vertx/mqtt/impl/MqttClientImpl.java b/src/main/java/io/vertx/mqtt/impl/MqttClientImpl.java index e4fabe35..f528e85a 100644 --- a/src/main/java/io/vertx/mqtt/impl/MqttClientImpl.java +++ b/src/main/java/io/vertx/mqtt/impl/MqttClientImpl.java @@ -52,6 +52,7 @@ import io.vertx.core.internal.logging.Logger; import io.vertx.core.internal.logging.LoggerFactory; import io.vertx.core.net.NetClient; +import io.vertx.core.net.SocketAddress; import io.vertx.mqtt.MqttClient; import io.vertx.mqtt.MqttClientOptions; import io.vertx.mqtt.MqttConnectionException; @@ -168,6 +169,18 @@ int getInFlightMessagesCount() { } } + + @Override + public SocketAddress localAddress() { + return connection.localAddress(); + } + + @Override + public SocketAddress remoteAddress() { + return connection.remoteAddress(); + } + + @Override public Future connect(int port, String host) {