NanoHTTPD
2016-06-15 10:50:25 0 举报
NanoHTTPD是一个轻量级的Java HTTP服务器,专为嵌入式系统和资源受限环境设计。它非常小巧,只有约70KB的源代码,但功能却相当强大。NanoHTTPD支持GET和POST请求,可以处理简单的文本和二进制数据。此外,它还支持文件服务、CGI脚本和其他高级功能。NanoHTTPD易于集成到其他项目中,可以作为独立的HTTP服务器运行,也可以与其他网络库(如SocketCAN)一起使用。总之,NanoHTTPD是一个适用于各种应用场景的高性能、低资源占用的HTTP服务器解决方案。
作者其他创作
大纲/内容
这是默认实现
进入Response.send(OutputStream outputStream)中
decodeHeader();Response r1=this.serve(this);r1.setRequestMethod(this.method);r1.send(this.outputStream);
PrintWriter ioe=new PrintWriter(outputStream);
public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session)
AsyncRunner
+ exec(Runnable var1)
start()
outputStream.flush();NanoHTTPD.safeClose();
Yes
进入session.execute()方法中
Method method=session.getMethod();
this.requestMethod!=Method.HEAD&&this.chunkedTransfer
NanoHTTPD.Method.PUT(equals(method)||NanoHTTPD.Method.POST.equals(method)
Socket e=myServerSocket.accept()
No
需要自己覆写public Response serve(IHTTPSession session)方法
HashMap files=new HashMap();session.parseBody(files);
DefaultAsyncRunner
+exec(Runnable code){ ++this.requestCount;Thread t=new Thread(code);t.setDaemon(true);t.setName(\"NanoHttpd Request Processor (#\"+ this.requestCount+\")\");t.start();}
0 条评论
下一页