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

70
LINES

< > BotCompany Repo | #1001225 // Check my host name(s) by contacting myself

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

Libraryless. Click here for Pure Java version (1112L/8K/27K).

1  
!747
2  
3  
m {
4  
  static long timeout = 5000;
5  
  
6  
  p {
7  
    final S pivot = randomID(6);
8  
    
9  
    new L<S> myNames;
10  
    
11  
    makeAndroid_forcePublic = true;
12  
    makeAndroid_allowVMInspection = false;
13  
    Android android = makeAndroid2("", stringfunc { pivot }, false);
14  
    ServerSocket server = startDialogServer_serverSocket;
15  
    
16  
    for (S name : litlist("tinybrain.de", "second.tinybrain.de"/*, "google.de"*/)) {
17  
      print("Checking " + name);
18  
      boolean result = isItMe(name, android.port, pivot, timeout);
19  
      print("  => " + result);
20  
      if (result) myNames.add(name);
21  
    }
22  
    
23  
    print("My names: " + structure(myNames));
24  
    
25  
    server.close(); // TODO: close the client connections
26  
    
27  
    //sleepSeconds(2);
28  
    //listUserThreadsWithStackTraces();
29  
    //System.exit(0);
30  
    
31  
    // SHOULD now exit properly by itself
32  
  }
33  
  
34  
  !include #1000915 // Flag class
35  
  
36  
  static boolean isItMe(final String name, final int port, final S pivot, long timeout) {
37  
    final new Flag ok;
38  
    final new Flag done;
39  
    
40  
    Thread t = new Thread("Talking to " + name + ":" + port) {
41  
      public void run() {
42  
        try {
43  
          DialogIO io = talkTo(name, port);
44  
          print("Connected to " + name + ":" + port + ".");
45  
          if (!io.waitForLine())
46  
            return;
47  
          S line = io.readLineNoBlock();
48  
          io.sendLine("please give pivot");
49  
          if (!io.waitForLine())
50  
            return;
51  
          line = io.readLineNoBlock();
52  
          print("Line read: " + quote(line));
53  
          io.close();
54  
          if (pivot.equals(line))
55  
            ok.raise();
56  
        } catch (RuntimeException e) {
57  
          print("[internal] " + e);
58  
        } finally {
59  
          done.raise();
60  
        }
61  
      }
62  
    };
63  
    t.start();
64  
    
65  
    done.waitUntilUp(timeout);
66  
    print("Interrupting thread.");
67  
    t.interrupt();
68  
    return ok.isUp();
69  
  }
70  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001225
Snippet name: Check my host name(s) by contacting myself
Eternal ID of this version: #1001225/1
Text MD5: eaaca8ecf72fb48519d43cc31fece3f6
Transpilation MD5: 0021a390c243377a5151c440f1bb4a13
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-03 19:25:19
Source code size: 1930 bytes / 70 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 537 / 577
Referenced in: [show references]