2

I want to send data from a device to an Android Phone.The Android Phone and
device are connected through hotspot. i.e. Device is connected to Android phone through hotspot of Android.The device has capability to send data over sockets provided an IP and port. what destination IP should I provide to the device so that it can connect to my Android device on a given port. I have written the corresponding code on Android device to receive connection on a given port.

Asus gates
  • 380
  • 1
  • 5
  • 20

1 Answers1

0

The Android phone will act as the gateway for your other device. Therefore, to find the IP of the Android phone from the other device, you have to inspect the routing information to get the IP of the gateway.

Command line

On the device connected to the access point provided by the Android phone:

$ ip route
default via 192.168.43.1 dev wlan0
...

You can validate this information by checking the IP of your Android phone:

$ adb shell ip addr
...
6: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP>
...
    inet 192.168.43.1/24 brd 192.168.43.255 scope global wlan0

This should show you the IP assigned to the WiFi interface of your Android phone. It should match the gateway IP seen on your other device.

From code

If you have to obtain the gateway IP automatically, check here for some code examples.