Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

34
LINES

< > BotCompany Repo | #1000436 // Android/desktop: Web server test using NanoHTTPD on port 8888, shortened

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1999L/16K/40K).

1  
!747
2  
3  
class MyHTTPD extends NanoHTTPD {
4  
  public MyHTTPD(int port) throws IOException { super(port); }
5  
6  
  public Response serve(String uri, Method method,
7  
      Map<S, S> header, Map<S, S> parms, Map<S, S> files) {
8  
    System.out.println( method + " '222" + uri + "' " );
9  
    String msg = "<html><body><h1>Hello server</h1>\n";
10  
    
11  
    if (parms.get("username") == null)
12  
        msg +=
13  
            "<form action='?' method='get'>\n" +
14  
            "  <p>Your name: <input type='text' name='username'></p>\n" +
15  
            "</form>\n";
16  
    else
17  
        msg += "<p>Hello, " + parms.get("username") + "!</p>";
18  
19  
    msg += "</body></html>\n";
20  
    return newFixedLengthResponse(msg);
21  
  }
22  
}
23  
24  
m {
25  
  static int port = 8888;
26  
  static MyHTTPD server;
27  
  
28  
  p {
29  
    server = new MyHTTPD(port);
30  
    server.start();
31  
  }
32  
}
33  
34  
!include #1000433 // class NanoHTTPD

Author comment

Began life as a copy of #1000435

download  show line numbers  debug dex  old transpilations   

Travelled to 18 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, mrjhfnjfopze, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, tzxuzeklshpk, vouqrxazstgt, xinetxnxrdbb

Comments [hide]

ID Author/Program Comment Date
1118 stefan Works on Linux 2015-10-07 20:49:20

add comment

Snippet ID: #1000436
Snippet name: Android/desktop: Web server test using NanoHTTPD on port 8888, shortened
Eternal ID of this version: #1000436/1
Text MD5: 9264b382e1fe1fd338468de42d03e17f
Transpilation MD5: 0f80b6b671145f094d794e51706dfe49
Author: stefan
Category: javax android
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-07 20:50:04
Source code size: 878 bytes / 34 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 937 / 1682
Referenced in: [show references]