Timeout Error When Connecting Localhost Api With Android Studio On Real Devices Through Usb
Solution 1:
I disabled the Firewall and everything is working perfectly.
Solution 2:
Your access to local host via IPV4 works on emulator because your emulator and the host are on same network. It gives timeout on real device because, real device is not connected to same network as your host by just connecting through USB.
There are two approaches:
Ensure your device and host share the same network. It could be by connecting your device to host network through Wifi.
If you cannot connect your device to the same network due to some constraints, then you can run following command:
adb reverse tcp:<localhost-port> tcp:<localhost-port>
Then use localhost
instead of IPV4 in your URL
Solution 3:
Your Network firewall Blocks the connection to localhost. To resolve this you can do :
In windows
1st Method Add Inbound rule (Recommended)
Create a new inbound rule with Windows Firewall with Advanced Security. The type in this case would be port, then on the next page you enter 8080 as the port. On the next page select either "Allow the connection", or "Allow the connection if it is secure". Select when the rule applies, and finally give the rule a name.
Connect the localhost api through the new allowed port.
Use
ip-address
of the localhost instead oflocalhost
.
2nd Method Turn of firewall.
In Linux
1. Add IPTable Entry
- You can learn adding incoming and outgoing rules using ssh and http in Linux here
Post a Comment for "Timeout Error When Connecting Localhost Api With Android Studio On Real Devices Through Usb"