Nanohttpd在android系统 [英] Nanohttpd in android

查看:505
本文介绍了Nanohttpd在android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让它使用nanohttp创建一个Web服务器在此code不给我一个错误的Andr​​oid应用程序,但是当我在浏览器上的8000端口键入IP地址它说,连接超时,请帮帮忙将在这里appriciated那张code ..

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...

推荐答案

你在哪里使用类似新MyHTTPDs()。开始()?你需要从你的类创建一个实例,然后用开始启动服务器()方法。

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.

这篇关于Nanohttpd在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆