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

46
LINES

< > BotCompany Repo | #1014671 // Counting Test Through WebSocket (OK)

JavaX source code (desktop) [tags: butter use-pretranspiled] - run with: x30.jar - homepage

Download Jar. Libraryless. Click here for Pure Java version (2228L/14K).

!7

static Set webSockets = synchroHashSet();
static long counter;

p {
  replaceCollection(webSockets, subBot_getMyWebSockets());
  print("Have " + n2(webSockets, "web socket") + ".");
  doEvery(1000, f count);
}

html {
  ret loadJQuery()
    + "Counting:"
    + hdiv("", id := 'results)
    + hreconnectingWebSockets()
    + hjavascript([[
      var ws = new ReconnectingWebSocket("${URI}");
      ws.onmessage = function(event) {
        var d = event.data;
        $("#results").html(d);
      };
    ]].replace("${URI}", subBot_myWebSocketURI());
}

svoid count {
  ++counter;
  if (empty(webSockets)) ret;
  print("Sending " + counter + " to " + n2(webSockets, "socket"));
  for (O ws : webSockets)
    pcall(ws, 'send, str(counter));
}

static void onNewWebSocket(O ws, S uri) {
  print("New web socket!");
  webSockets.add(ws);
}

static void onWebSocketMessage(O ws, S msg) {
  print("Got message: " + msg);
}

static void onWebSocketClosed(O ws) {
  print("Closed web socket");
  webSockets.remove(ws);
}

Author comment

Began life as a copy of #1014667

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1014671
Snippet name: Counting Test Through WebSocket (OK)
Eternal ID of this version: #1014671/13
Text MD5: a659ebd7f040196810c111597d9f126d
Transpilation MD5: 9fafe3eaa7e6297096413c20a3fccac1
Author: stefan
Category: javax / web
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-04-29 22:31:23
Source code size: 1060 bytes / 46 lines
Pitched / IR pitched: No / No
Views / Downloads: 443 / 1038
Version history: 12 change(s)
Referenced in: [show references]