I'm trying to connect my Android application with Tomcat web server running in the same computer.
This Activity is simple, only shows the HTML code from the index page of a server. It works with whatever URL on Internet, but I'm having problems getting the index page of my own Tomcat server (from my browser with "http://localhost:8080", there isn't any problem)
Using java Syntax Highlighting
- public class Localizador extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- EditText edit = new EditText(this);
- String server = "10.0.2.2";
- int port = 8080;
- try {
- Socket socket = new Socket( server, port);
- BufferedReader in = new BufferedReader(
- new InputStreamReader( socket.getInputStream() ) );
- PrintWriter out = new PrintWriter(
- new OutputStreamWriter( socket.getOutputStream() ),true );
- out.println("GET /" );
- String line = null;
- while( (line = in.readLine()) != null ) {
- edit.append(line);
- }
- socket.close();
- setContentView(edit);
- } catch( IOException e ) {
- edit.setText("Error: " + e.getMessage());
- setContentView(edit);
- }
- }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
I have read here (http://code.google.com/android/kb/commo ... lhostalias) I need use the IP 10.0.2.2 referer to localhost, but it doesn't work !
I have no clue about the problem and I'm sure it's a nonsense.
Please, could somebody help me to connect my Android application with my Tomcat server, running on the same host?
Thanks a lot in advance


