From 0f07346eacb516ad690de5615ec18455b87b5fe1 Mon Sep 17 00:00:00 2001 From: Andy Prock Date: Tue, 21 Feb 2017 11:43:46 -0800 Subject: [PATCH] eliminate the reverse dns lookup when connecting --- .../main/java/com/peel/react/TcpSockets.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/com/peel/react/TcpSockets.java b/android/src/main/java/com/peel/react/TcpSockets.java index a627457..1bc07d2 100644 --- a/android/src/main/java/com/peel/react/TcpSockets.java +++ b/android/src/main/java/com/peel/react/TcpSockets.java @@ -21,6 +21,7 @@ import com.facebook.react.bridge.WritableMap; import com.facebook.react.modules.core.DeviceEventManagerModule; import java.io.IOException; +import java.net.InetAddress; import java.net.Inet6Address; import java.net.InetSocketAddress; import java.net.UnknownHostException; @@ -160,10 +161,12 @@ public final class TcpSockets extends ReactContextBaseJavaModule implements TcpS WritableMap infoParams = Arguments.createMap(); infoParams.putInt("id", clientId); + final InetAddress address = socketAddress.getAddress(); + WritableMap addressParams = Arguments.createMap(); - addressParams.putString("address", socketAddress.getHostName()); + addressParams.putString("address", address.getHostAddress()); addressParams.putInt("port", socketAddress.getPort()); - addressParams.putString("family", socketAddress.getAddress() instanceof Inet6Address ? "IPv6" : "IPv4"); + addressParams.putString("family", address instanceof Inet6Address ? "IPv6" : "IPv4"); infoParams.putMap("address", addressParams); eventParams.putMap("info", infoParams); @@ -172,17 +175,19 @@ public final class TcpSockets extends ReactContextBaseJavaModule implements TcpS } @Override - public void onConnect(Integer id, InetSocketAddress address) { + public void onConnect(Integer id, InetSocketAddress socketAddress) { if (mShuttingDown) { return; } WritableMap eventParams = Arguments.createMap(); eventParams.putInt("id", id); + final InetAddress address = socketAddress.getAddress(); + WritableMap addressParams = Arguments.createMap(); - addressParams.putString("address", address.getHostName()); - addressParams.putInt("port", address.getPort()); - addressParams.putString("family", address.getAddress() instanceof Inet6Address ? "IPv6" : "IPv4"); + addressParams.putString("address", address.getHostAddress()); + addressParams.putInt("port", socketAddress.getPort()); + addressParams.putString("family", address instanceof Inet6Address ? "IPv6" : "IPv4"); eventParams.putMap("address", addressParams);