3

My android client makes a URLconnection to a servlet deployed on jboss. But when i run the client in emulator there seems to be no connection being established. My client code:

URL url = new URL("http://192.168.56.1:8080/hello");
              URLConnection connection = url.openConnection();
              connection.setDoOutput(true);
              ObjectOutputStream out=new ObjectOutputStream(connection.getOutputStream());
                String s=new String("success");
                out.writeObject(s);
                out.flush();
                out.close();

There is no response in jboss. 192.168.56.1 is the ip address of my machine. Since 'localhost' will refer to the emulator itself, I have used 192.168.56.1.(ipcofig) What is the problem.

This is after I made the suggested changes(i.e gave the internet permission in android manifest.xml and changed the url to 'http://10.0.2.2:8080/hello' to refer to my machine). But i still get this exception when I run my application(Client):

ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.Client/.ClientActivity } from null (pid=-1, uid=-1) requires android.permission.INTERNET

Now it is working. I added the in internet permission to the manifest tag. Earlier I had added it inside the application tag. With reference to my original question, still there is no response from the jboss server evene after making all the suggested changes. There seems to be no connection being made between the emulator and the jboss server.

Ashwin
  • 12,691
  • 31
  • 118
  • 190

1 Answers1

2

So assuming your JBoss server is running on the same PC as your emulator, here are a few things you can check:

First off, make sure you have the Internet permission set in your AndroidManifest.xml as Thinksteep pointed out:

<uses-permission android:name="android.permission.INTERNET" />

Secondly, try changing the IP address in:

URL url = new URL("http://192.168.56.1:8080/hello");

To:

URL url = new URL("http://10.0.2.2:8080/hello");

Details here. Essentially what this is doing is that assuming you have your JBoss serving off localhost on your development machine (i.e. serving off 127.0.0.1), your emulator should be able to connect via this special IP address.

Community
  • 1
  • 1
Marvin Pinto
  • 30,138
  • 7
  • 37
  • 54
  • I only added the internet permission in my android.xml file. I have set the permissions to include internet permission.but while running the following exception occurs.ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.epramaan/.EpramaanActivity } from null (pid=-1, uid=-1) requires android.permission.INTERNET – Ashwin Feb 08 '12 at 01:37
  • Please see my second edit. No exceptions now. But still no response from the jboss server. – Ashwin Feb 08 '12 at 02:16
  • @user1139023 Is your JBoss server serving off `127.0.0.1` or `192.168.56.1`? If the latter, are the proper firewall ports opened? Are you able to connect to it from _another_ PC? (just to see if it's alive) – Marvin Pinto Feb 08 '12 at 02:19
  • the jboss serving is serving off 127.0.0.1. – Ashwin Feb 08 '12 at 04:44
  • Finally got it. WHile testing with url connection I did not return back any value from the server. I just printed the value sent from the android client. Thank You – Ashwin Feb 08 '12 at 05:18