-1

I am trying to connect an android phone to a server running on my local machine over http and outputstream the content but unsuccessful..!

here is my code :

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {

        URL url = new URL("http://192.168.24.42:80/DebugServer/");
        HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();     
        InputStream in = new BufferedInputStream(urlConnection.getInputStream());
        readStream(in);
        urlConnection.disconnect();

    } catch (IOException e) {
        e.printStackTrace();
}


private void readStream(InputStream in) {

    try {
        in.read();
        in.read();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
3
  • Do you have a question?
    – Simon
    Aug 27, 2013 at 16:27
  • What error do you get ? Aug 27, 2013 at 16:29
  • Arent u supposed to connect to port 8080 ???
    – An SO User
    Aug 27, 2013 at 17:20

1 Answer 1

0
URL url = new URL("http://192.168.24.42:80/DebugServer/");  

is your connection URL. Change the port to 8080 because that is where the server listens to.

Also, did you go to the bin folder of your tomcat (I am assuming that here) and run the startup.BAT or startup.SH file because without that your server is not running.

To check if your server is properly running, try http://localhost:8080
And please, post the logcat :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.