6

I am working with an App in Android. It uses a local host server in my PC to get some data. But I am getting warning in LotCat like this after running.

02-07 15:51:48.965: W/System.err(10339): com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 9090): connect failed: ECONNREFUSED (Connection refused)

I am using a real device to connect to PC and run my App. android:permission:internet has been enabled in AndroidManifest.xml. The real device which I am using is hTC mobile with Androidv4.2.2. I am not using an asyncTask to call this webservice. Can anyone please help me....

twlkyao
  • 14,302
  • 7
  • 27
  • 44
user3060070
  • 61
  • 1
  • 1
  • 4
  • 4
    Use network ip instead `localhost/127.0.0.1` while testing on real device.... Refer this [android-device-connection-with-localhost-server](http://stackoverflow.com/questions/21252879/android-device-connection-with-localhost-server/21253020#21253020) – Chirag Ghori Feb 07 '14 at 11:21
  • 2
    If you are using on localhost, try using 10.0.0.2 or 10.0.2.2 as proxy in Emulators or device's network setting – ajitksharma Feb 07 '14 at 11:23
  • I changed it to my system ip address. But coming as connection timed out. Is it because i am not using asyncTask?.. – user3060070 Feb 07 '14 at 11:36
  • There might be configuration problem with your Wampserver. Make sure that your Wampserver is configured to receive requests from LAN? – Khawar Raza Feb 07 '14 at 13:39
  • There's a change in my url, now not a local host server. The same url when i am trying to access from my mobile's browser its showing webpage not available. I am able to open from my pc.. I am using mobile data connection(3G) in my mobile. – user3060070 Feb 10 '14 at 04:44
  • did you solve the problem? I am currently having the same issue. – MKS Mar 19 '14 at 02:11
  • Yes i solved. It was because i was using mobile data connection. I connected to wifi. now its working fine. – user3060070 Mar 20 '14 at 03:07
  • Make sure your mobile and localhost are connected to same internet. That means your both devices should have `same IP address`. – Mohammed Farhan Jul 24 '17 at 05:07

1 Answers1

0

The URL should be 127.0.0.1:9090/URI.

Furthermore ensure that you are on the same network as your server i.e make sure you are on the same wifi connection on the device as the server is on.

If this does not work the port may already be in use and you should try another port such as 4444.

JH95
  • 489
  • 1
  • 7
  • 24
  • The port isn't in use at all. That's why the OP got 'connection refused'. If it was in use he would have connected to it. And 127.0.0.1:9090 is already exactly what he's connecting to, – user207421 Jan 21 '15 at 06:47