0

i want to make a android app which uses nanohttp to create a web server this code do not give me a error but when i type the ip addr in browser on port 8000 it says connection timed out please help any help will be appriciated here goes the code..

package dolphin.developers.com;

import java.io.File;
import java.io.IOException;
import java.util.Properties;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import dolphin.devlopers.com.R;

public class AnroidWebServerActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
 }



public  class MyHTTPDs extends NanoHTTPD_2 {

public MyHTTPDs(int port, File wwwroot) throws IOException {
        super(8000,new File("."));
        // TODO Auto-generated constructor stub
    }


 @Override
public Response serve( String uri, String method, Properties header, Properties parms, Properties files ) {
    File rootsd = Environment.getExternalStorageDirectory();
    File path = new File(rootsd.getAbsolutePath() + "/");
    Response r = super.serveFile("index.htm.html", header, path, true);
    return r;

}
}}

and the log cat does not give me any error so i am not posting it...

Prakhar
  • 2,270
  • 19
  • 26
  • There are many Android developer sites on the Internet, offering assistance in many languages. I have several sites listed at http://www.andglobe.com. You may have better luck using a site that is in a language that is more comfortable for you. – CommonsWare Jul 23 '13 at 12:30

1 Answers1

1

Where are you using something like new MyHTTPDs().start()? You need to create an instance from your class and then start the server with the start() method.

f1sh
  • 11,489
  • 3
  • 25
  • 51
  • You probably know that when your application is launched certain activity is called, if that happens its onCreate method is called, so it is for sure best place to put start() method. In code that you paste here, your onCreate method only loads proper layout, you have inner class of your nanoHTTPD server but it isn't called anywhere. You can check some extra info about nanoHTTPD here http://stackoverflow.com/questions/14309256/using-nanohttpd-in-android/15523927#15523927 – MP23 Oct 19 '13 at 00:34