• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connection Refused

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys.

I am new to android programming.

I tried to access the localhost in my laptop using my android phone.

To check the connection I supply thiis code:

try {
HttpClient httpclient = new DefaultHttpClient();


HttpPost httppost = new HttpPost(
"http://10.0.2.2/ssmis/acess1.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
System.out.println("connected!");
} catch (Exception e) {
Log.e("log_tag", "Error in http connection" + e.toString());
}



However the logcat gives me an error that says that I have error in HttpConnection and that the connection is refused.

I also tried to supply many addresses in HttPost Constructor but nothing worked like http://192.168.10.7/ (which is my IPv4 address)

Note that I used my android phone as emulator and I am not using AVD.

So what should I do?

Your responses will be very much appreciated.

Thank you!





 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does "using the Android phone as the emulator" mean? How is the device connected to the network?
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you provided the proper permission in your manifest?

 
Jc Frane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Ulf Ditmer - what I mean is I used my physical handphone for testing and I am connected to the network through Wifi.

@Maneesh Godbole - not yet sir, i'll try it =)

Thanks for your reply.
 
Jc Frane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,

still can't connect even i supplied android permission to use net.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the IP address of the server? It can't be both 10.0.2.2 and 192.168.10.7. Can you ping that address from the device? An app like the one linked in my profile can test that.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic