作家
登录

在Android上实现HttpServer

作者: 来源: 2017-08-16 09:10:45 阅读 我要评论

static final String TAG = "NIOHttpServer"
  •  
  •     private static NIOHttpServer mInstance; 
  •  
  •     public static int PORT_LISTEN_DEFALT = 5000; 
  •  
  •     AsyncHttpServer server = new AsyncHttpServer(); 
  •  
  •     public static NIOHttpServer getInstance() { 
  •         if (mInstance == null) { 
  •             // 增长类锁,包管只初始化一次 
  •             synchronized (NIOHttpServer.class) { 
  •                 if (mInstance == null) { 
  •                     mInstance = new NIOHttpServer(); 
  •                 } 
  •             } 
  •         } 
  •         return mInstance; 
  •     } 
  •  
  • //模仿nanohttpd的写法 
  •     public static enum Status { 
  •         REQUEST_OK(200, "请求成功"), 
  •         REQUEST_ERROR(500, "请求掉败"), 
  •         REQUEST_ERROR_API(501, "无效的请求接口"), 
  •         REQUEST_ERROR_CMD(502, "无效敕令"), 
  •         REQUEST_ERROR_DEVICEID(503, "不匹配的设备ID"), 
  •         REQUEST_ERROR_ENV(504, "不匹配的办工作况"); 
  •  
  •         private final int requestStatus; 
  •         private final String description; 
  •  
  •         Status(int requestStatus, String description) { 
  •             this.requestStatus = requestStatus; 
  •             this.description = description; 
  •         } 
  •  
  •         public String getDescription() { 

  •   推荐阅读

      还不知道这11个超酷的编程新工具你就 out 了!

    对象对开辟人员来说至关重要。对象可以让一个开辟人员的日常工作更高效,并且只须要存眷最重要的工作。对于开辟人员来讲,寻找更好的替代对象往往比保持应用熟悉过时的对象更艰苦。你可能>>>详细阅读


    本文标题:在Android上实现HttpServer

    地址:http://www.17bianji.com/lsqh/36730.html

  • 关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)