Rapsssito / react-native-tcp-socket

React Native TCP socket API for Android, iOS & macOS with SSL/TLS support.
MIT License
304 stars 80 forks source link

remoteAddress returns host name, not IP address. #110

Closed dlguswo333 closed 3 years ago

dlguswo333 commented 3 years ago

Description

According to the name and Node.js net module description, remoteAddress should return the IP address of the remote, but it returns host name of the machine at least in android.

Steps to reproduce

Steps to reproduce the behavior:

  1. Connect to any remote machine.
  2. Get the remote address with socket.remoteAddress.

Current behavior

It returns the host name of the remote machine.

Expected behavior

It returns the IP address of the remote machine.

Relevant information

OS Android 10
react-native 0.64.1
react-native-tcp-socket v5.2.0

Looking at the java codes, it looks clear why it occurs. In onConnect function in TcpSocketModule.java, https://github.com/Rapsssito/react-native-tcp-socket/blob/991af02d8075e50f98e438217e4525bb09345c10/android/src/main/java/com/asterinet/react/tcpsocket/TcpSocketModule.java#L268 remoteAddress is set to the host name of the remote address.

https://github.com/Rapsssito/react-native-tcp-socket/blob/991af02d8075e50f98e438217e4525bb09345c10/android/src/main/java/com/asterinet/react/tcpsocket/TcpSocketModule.java#L333 Same goes with onConnection function.

In my opinion, the line should be somewhat like this:

        connectionParams.putString("remoteAddress", remoteAddress.getAddress().getHostAddress());

The above is from my forked repository.

It would be great if you take a look at this issue. Thank you for your awesome module.

Rapsssito commented 3 years ago

@dlguswo333, thanks for the feedback! You are correct, this is a bug.

Rapsssito commented 3 years ago

Fixed!