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

68
LINES

< > BotCompany Repo | #1000928 // Chat client

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

Libraryless. Click here for Pure Java version (2155L/16K/50K).

!747


!1000868 // dialogHandler {

m {
  static int chatPort = 9751; // just any number, but must match the server's number.
  static S programID; // filled by JavaX

  static abstract class DialogIO {
    abstract boolean isStillConnected();
    abstract String readLineNoBlock();
    abstract boolean waitForLine();
    abstract void sendLine(String line);
    abstract void close();
  }
  
  p {
    installHelloMessage(programID + " - Chat client");
    
    startChatServerIfNotUp();
    waitForChatServer();
    
    final Socket s = new Socket("localhost", chatPort);    
    print("connect");
    
    final Writer w = new OutputStreamWriter(s.getOutputStream(), "UTF-8");
    final BufferedReader in = new BufferedReader(
      new InputStreamReader(s.getInputStream(), "UTF-8"));
    DialogIO io = new DialogIO() {
      S line;
      boolean buff;
      
      boolean isStillConnected() {
        return !(buff || s.isClosed());
      }
      
      String readLineNoBlock() {
        S l = line;
        line = null;
        return l;
      }
      
      boolean waitForLine() ctex {
        if (line != null) return true;
        print("Readline");
        line = in.readLine();
        print("Readline done: " + line);
        if (line == null) buff = true;
        return line != null;
      }
      
      void sendLine(String line) ctex {
        w.write(line + "\n");
        w.flush();
      }
      
      void close() ctex {
        s.close();
      }
    };
  
    //io.waitForLine();
    io.sendLine("hello chat");
    print("Sent line.");
    io.close();
    print("Closed.");
  }
}

Author comment

Began life as a copy of #1000867

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: #1000928
Snippet name: Chat client
Eternal ID of this version: #1000928/1
Text MD5: dbe9b8e66a6f0c3d876d226f0162bc8e
Transpilation MD5: 3a76e7eedea886976d786262ee7b5a82
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-10 00:05:24
Source code size: 1675 bytes / 68 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 704 / 718
Referenced in: [show references]