Search code examples
androidlibcurlcocos2d-x

libcurl & android connecting to a web service at localhost


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?


Solution

  • 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.