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

49
LINES

< > BotCompany Repo | #1000699 // THIS is a database.

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

Libraryless. Click here for Pure Java version (2124L/16K/49K).

!636
!modern

main {
  static new L<S> database;
  
  static PrintWriter out;
  static BufferedReader in;
  
  psvm {
    ServerSocket ss = new ServerSocket(8888);
    print("port 8888 yo");
    while (true) {
      print("and again!");
      Socket clientSocket = ss.accept();
      print("bing!");
      out = new PrintWriter(clientSocket.getOutputStream(), true);
      in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
      //out.println("Hello!");
      try {
        onClient();
      } catch (RuntimeException e) { // don't die policy except on OutOfMemoryError (bad)
        e.printStackTrace();
      }
      print("zap.........");
      clientSocket.close();
    }
  }
  
  static S read_line_from_client() ctex { // we don't like "IOExceptions"
    return in.readLine();
  }
  
  static void write_to_client(S s) {
    out.println(s);
  }
  
  static void disconnect_from_client() {
    // we do it anyway when the code is through
  }

  static void onClient() {
    S s = read_line_from_client();
    database.add(s);
    print(quote(s) + "... oh yeah.");
    write_to_client("Thank you. You are number " + database.size() + " in our system.");
    disconnect_from_client();
  }
}

Author comment

Began life as a copy of #1000698

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1000699
Snippet name: THIS is a database.
Eternal ID of this version: #1000699/1
Text MD5: 2144c959e1c8f276508c5e57ceb64015
Transpilation MD5: 2b68d2f8a51020a11f66103737d0b69e
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-23 00:22:56
Source code size: 1270 bytes / 49 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 604 / 642
Referenced in: [show references]