libcurl & android connecting to a web service at localhost - android

I've managed to connect my app to a web service but I have a problem with the android platform. (If someone doesn't know, with cocos2d-x you can make multiplatform apps)
Right now, the web service is hosted at "http://127.0.0.1:9876/ts?wsdl" at localhost.
I've managed to generate requests for it and it works great in the win32 app. The problem comes when I try to connect to the web service with the android app. It will always give "code: 7" (couldn't connect) but the funny thing is that it will work if I connect to whatever hosted server.
So I wonder why it won't let me connect to localhost, also note that I'm using the emulator since I don't have a device but I don't think that's the problem.
Any ideas?

I assume you are using an emulator instead of a phone. So when you type localhost, it refers to the ip address of the phone, not your pc. Android provides you an ip address which maps to your PCs localhost. So use 10.0.2.2. instead of localhost and it should work.

Related

My android phone does not connect to my apache local server

I'm developing an android app that connect with a restful web service which is on my tomcat local server.
The app works well on the emulator, however, it doesn't work on my real mobile.
I use the IP from ipconfig, and both my laptop and my phone connected to the same Wi-Fi.
I tried to call the web service from the mobile browser but still, it doesn't see my localhost :(!
it shows me :
This site cannot be reached.
I searched a lot and all the solutions say that I have to connect both to the same Wi-Fi network and to use the IP from ipconfig command, which I did!
How can I fix this?
PS: I'm using 9090 as my port number, I don't know if that a reason?
Thank you.

How can i access my localhost XAMP server from my Android mobile?

When i run my project on Emulator than localhost servery is working but when run on real Android phone than localhost server not found. So how can i access my localhost server from my real Android Device. I use XAMP server.
You cannot access localhost from your mobile device because the server is limited to your system only. In order to test the application you have to run the application on emulator so that it could find the server. Although there is a way...if you are creating a whole server that is backend and you have a network to which your mobile and system is connected then you can set your server to listen to a port on that network. I used NodeJs to accomplish that. You can search some tutorials for using NodeJs through which you can access you xampp server. You can also try AdonisJs which is a framework for NodeJs for a better approach. But keep in mind that you need a common network through which your system and your mobile device is connected. It is a bit complicated method but yes that can work. Accessing localhost directly from system to your mobile device is not possible..if you want to avoid learning NodeJs then you'll have to keep using emulator for the testing but learning something new is always amazing. So i would suggest you to learn NodeJs . Anyways you can avoid all the trouble and keep testing your application using your emulator. I hope this answer will help you :)
You should have told which ip you used running on emulator.
Your client on the android device should use the ip of the computer where your server is running on.
Android device and server computer in same WLAN.
If your computer and mobile are connected through same internet line then you can use ip of your computer instead of localhost can do the work.
You cannot access the local host server from a different node eventhough both nodes are connected to same network only way is that change the ip configuration of server to 0.0.0.0: so that you can access the server from any node just by typing the ip of the server followed by port no...

How i can connect from localhost to android emulator?

Many people ask about "How get the connect from a emulator to localhost". I am asking about a reverse issue. I created a tiny http server in android app. I know his ip address and want to connect from my chrome browser to the app. If i use my a phone it is no problem, because app use "outer" ip, but in local net wifi. When i use a emulator on a development machine and open in browser ip 10.0.2.15 then can not get access to app in emulator. I tryed any ways - loopback, forward ... all is not working.

Android Simulator how does it connect to local IP addresses?

I am trying to implement an Android application in Windows 7 using Eclipse. I am trying to connect the Android simulator to the local test server in my company, but for some reason, it cannot connect to the test server.
If there is any settings or configurations for this, please let me know.
I have tried to do the same from a MAC machine using iPhone emulator and I am facing the same problem. How would this emulator connect to the local servers in my company as currently it all goes to live servers? What configurations are required to be done on the simulators, and how?
If I try to connect to the test server from normal Windows machine browser, I am able to successfully connect to it through the web browser; but when I try to do the same from the Android emulator browser, it cannot connect to it.
The emulator points to the live network and not the local network in my company. This is strange and I know that I need to do some settings for it, but I am not sure where these settings are done and how.
If accessing local computer:
http://localhost:8080/MyLocalServer.html // URL to use in computer browser
http://10.0.2.2:8080/MyLocalServere.html // URL to use in emulator browser
Also try using a local IP to connect to any local servers. Do not use host names.
Dont:
http://mylocalserver.org/
Do:
http://192.168.1.125:portnumber
You have to set up IP-based hosts instead of name-based.
Emulator its - VM. This use virtual network connection. I think you need before chech this connection (this connection may bee stay as NAT, Breedge, Native IP adress, Proxy).
Since you do not work iPhone emulator, most likely you, IP adress virtual network connectionб which uses Emulator, does not match the address area of the local network, and routing occurs
This may help you...
Taken from the android docs:
If you need to refer to your host computer's localhost, such as when you want the emulator client to contact a server running on the same host, use the alias 10.0.2.2 to refer to the host computer's loopback interface. From the emulator's perspective, localhost (127.0.0.1) refers to its own loopback interface.
http://developer.android.com/guide/faq/commontasks.html#localhostalias

Exposing a service running on localhost to an Android emulator?

I'm running a service through ASP.net/Visual Studio that's being developed in conjunction with an Android app. When I run the service through VS, it's accessible at http://localhost:13980/ but not http://127.0.0.1:13980/ (which gives a "bad request - invalid hostname" 400 error). Obviously, I can't tell the Android app to look for a service at "localhost" since that'll be pointing at itself.
I understand (according to this page) that the Android emulator treats 10.0.2.2 as a pass-through IP address to the host machine's 127.0.0.1, so it would stand to reason that everything would come together if I a) got localhost to be properly exposed through 127.0.0.1, and b) changed the target address in the app from localhost:port to 10.0.2.2:port.
How would I go about doing part A? I'm running Windows 8.1 Pro, Visual Studio 2012, and the project in question is targeting .NET 4.5.
Thanks!
You have two options:
Run the web service under IIS instead of VS Cassini. This way you can bind the web service to your local network's IP address, e.g. http://10.0.2.2:8081
Modify the hosts file on your Android emulator to redirect localhost to your computer's IP address
The second one isn't a great solution. It may cause some conflicts with the OS and I'm not even sure Cassini would still even serve the request. Visual Studio's in-built web server (Cassini) only listens to local requests, so option (1) really is the most flexible. Plus, since you have W8 Pro IIS is already built-in.
The IP address 10.0.2.2 IP maps to the the 127.0.0.1 IP address, not to localhost.
From the emulator, connect to 10.0.2.2, and then host your site on 127.0.0.1 instead of localhost. That should work.
Use the IP address 10.0.2.2 instead. See this:
How to connect to my http://localhost web server from Android Emulator in Eclipse

Categories

Resources