首页  

java HTTP Server NanoHttpd     所属分类 java 浏览量 846
nanohttpd

A simple, tiny, nicely embeddable HTTP 1.0 (partially 1.1) server in Java
最早的版本 只有一个文件

javac NanoHTTPD.java 
javac HelloServer.java 

java -cp . NanoHTTPD -p 7777 -d  .
http://127.0.0.1:7777


java -cp . HelloServer
http://127.0.0.1:8080


import java.io.*; import java.time.LocalDateTime; import java.util.*; public class HelloServer extends NanoHTTPD { public HelloServer() throws IOException { super(8080, new File(".")); } public Response serve( String uri, String method, Properties header, Properties parms, Properties files ) { System.out.println( method + " '" + uri + "' " ); String msg = "hello,NanoHTTPD,"+LocalDateTime.now(); return new NanoHTTPD.Response( HTTP_OK, MIME_HTML, msg ); } public static void main( String[] args ) { try { new HelloServer(); } catch( IOException ioe ) { System.err.println( "Couldn't start server:\n" + ioe ); System.exit( -1 ); } System.out.println( "Listening on port 8080. Hit Enter to stop.\n" ); try { System.in.read(); } catch( Throwable t ) {}; } }
https://gitee.com/dyyx/hellocode/tree/master/src/nanohttpd https://gitee.com/dyyx/hellocode/tree/master/nanohttpd-1.28

上一篇     下一篇
GO panic recover

GO字符串拼接

go socket 编程 echo server

java nio echo server

GO文件读取

Java锁升级过程