• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection Refused

 
Jc Frane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • 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!





 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "using the Android phone as the emulator" mean? How is the device connected to the network?
 
Maneesh Godbole
Saloon Keeper
Posts: 11311
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Hey guys,

still can't connect even i supplied android permission to use net.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic