Android - Can I change 10.0.2.2 to localhost? - android

My test server is iis express, so I can access only localhost:port.
But android emulator's localhost hostname is 10.0.2.2, it occur Bad Request error.
I want change 10.0.2.2 hostname to localhost.
Is it possible? How Can I change it?

Android emulator runs in a Virtual Machine and using 10.0.2.2 or 127.0.0.1 or localhost will point to the emulator's own loopback address.
Therefore localhost will not work as a base URL - instead of changing the name you could upgrade to the Url to http://10.0.2.2:8080.
For more info on this you can have a look at this Medium Post. There is also this question on SO which also addresses the same issue.

Related

How can I access my localhost from my physical Android device?

I have seen this question
I am creating a flutter app and restful API with Laravel.
it is work on AVD with url = "10.0.2.2:8000".
and my browsers on computer url = "localhost:8000".
I turned off the firewall on windows 10.
I can access to Xampp dashboard from my phone's browser "192.168.1.8:80" , but it doesn't work with port 8000
My computer Ip
Xampp server
Try this:
php artisan serve --host 0.0.0.0 --port 80
Just make sure that the port is free.
Reference: https://stackoverflow.com/a/30675683/5192105
php artisan serve --host=you ip address

Accessing node.js server on my local system using android app

I have a node.js server running on my local system which interacts with postgresql in the same system to fetch and save data. I want to access node.js server from my android app to save and fetch data from postresql. The problem is my app is not able to connect to localhost. As localhost for my phone is different from my local system and if I am providing my system's IP address then also its refusing the connection.
I made server listen to hostname '0.0.0.0'. Initially I was not providing any hostname as argument in server.listen i.e it was like
server.listen('portnumber') which I changed to
server.listen('portnumber', '0.0.0.0');
if you are using android emulator and trying to access the the host machine's
local host use IP address : 10.0.2.2
for genymotion use IP address: 10.0.2.3
this should allow you to access the host machine's local host, but you will have to change this IP address to local IP address when running app on a device and connected to same network, to access from other network you need to open port(port forwarding I guess) in your router and talk ask your ISP to do the same.
here's a link to similar question : here

Relative path name as Hostname Connection parameter Client using Datasnap and Delphi XE5 when running in Android device

In this video https://www.youtube.com/watch?v=vZItTDbB8cw and many others, one can learn how to configure a Datasnap Client Server System inside Delphi XE5.
This kind of system works very well when the hostname parameter is set using an IP Address :
The bad news are that the hostname IPAddress can change. That's why I need to set the relative path name of the host server as the HostName.
Consider these:
The hostname is actually resolving to the IP address of the server and the DataSnap server is actually running. I tested this by running the app in windows: I changed the hostname into the relative path name of the server and the connection worked well.
The problem becomes when I try to run the app in the android device: it does not recognize the connection when the hostname is set with the relative path name of the machine. What am I missing?
When you are referring to relative path of the machine are you talking about network name of the machine?
If the answer is yes then the problem is that your android device is not on the same sub-network than your host machine. This could only work if both your host machine and your mobile phone are on the same VPN.
Anyway the correct solution is to assign your server to some domain and then set that domain name as HostName in your client application.

SmartFoxServer unable to connect to server

I am working in android chat application.
I used SmartFox server. I am using 10.0.2.2 as server IP address and 9933 as Port.
Whenever i run this application using emulator then works fine but when i run this application in my real device then connection does not performed correctly. I think this is unable to find out IP 10.0.2.2.
I changed this IP address to 192.168.1.9 which is IP address of my system in LAN on which SmartFox server is installed.
Please suggest me what mistake i have done.
Thank you in advance.
I resolved my problem myself. I created one entry in confi/server.xml file of server.
like this:-
<serverSettings>
<socketAddresses>
<socket address="192.168.1.9" port="22" type="TCP"/>
<socket address="192.168.1.9" port="22" type="UDP"/>
</serverSettings>
</socketAddresses>
or you may add this entry using admin module of Smartfox server. This task can be done using Server configuration part.

How do you access a local port 8080 url from an android http get

I have a restful web service located on a local tomcat instance.
I'm trying to access the url via a get in my application but am getting the error: host is unresolved
I try to access this url from my android emulator browser to confirm the connection there and am unable to get to it their either. An alert comes up on the screen that says: "an sd card is required to download 125562.bin"
I am not using localhost in my url but something that looks like:
http://192.168.1.2:8080/service/0/12345
It returns straight json
Does anyone know why I can't access this in the android emulator? I can successfully hit this same address from my computer browser as well as iPhone and it brings back json.
Does android handle other ports differently than standard port 80? Is the problem this url doesn't have an extension?
The Android-Emulator has a virtual router, which cut's the Emulators network from the host-computers network.
However, this router is part of the network, too and enables you to access servers running on the local machine by using the IP 10.0.2.2.
So you would use:
http://10.0.2.2:8080/service/0/12345
You need to use 10.0.2.2 to emulate your local machine's 'localhost'.
See Emulator Networking

Categories

Resources