Download Jar. Libraryless. Click here for Pure Java version (2228L/14K).
1 | !7 |
2 | |
3 | static Set webSockets = synchroHashSet(); |
4 | static long counter; |
5 | |
6 | p { |
7 | replaceCollection(webSockets, subBot_getMyWebSockets()); |
8 | print("Have " + n2(webSockets, "web socket") + "."); |
9 | doEvery(1000, f count); |
10 | } |
11 | |
12 | html { |
13 | ret loadJQuery() |
14 | + "Counting:" |
15 | + hdiv("", id := 'results) |
16 | + hreconnectingWebSockets() |
17 | + hjavascript([[ |
18 | var ws = new ReconnectingWebSocket("${URI}"); |
19 | ws.onmessage = function(event) { |
20 | var d = event.data; |
21 | $("#results").html(d); |
22 | }; |
23 | ]].replace("${URI}", subBot_myWebSocketURI()); |
24 | } |
25 | |
26 | svoid count { |
27 | ++counter; |
28 | if (empty(webSockets)) ret; |
29 | print("Sending " + counter + " to " + n2(webSockets, "socket")); |
30 | for (O ws : webSockets) |
31 | pcall(ws, 'send, str(counter)); |
32 | } |
33 | |
34 | static void onNewWebSocket(O ws, S uri) { |
35 | print("New web socket!"); |
36 | webSockets.add(ws); |
37 | } |
38 | |
39 | static void onWebSocketMessage(O ws, S msg) { |
40 | print("Got message: " + msg); |
41 | } |
42 | |
43 | static void onWebSocketClosed(O ws) { |
44 | print("Closed web socket"); |
45 | webSockets.remove(ws); |
46 | } |
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: | 445 / 1044 |
Version history: | 12 change(s) |
Referenced in: | [show references] |