!7 set flag webSocketManager_debug. static Map wsToState = weakHashMap(); static long timeout = 30000+10000; // idle time + latency static ConnectedInstances cI; static ReliableSingleThread rst = new(r update); static int theNumber; sclass State { S computerID; int countSeen = -1; } p { cI = new ConnectedInstances; cI.connected2.onChange(rst); webSocketManager = new WebSocketManager { void onNewWebSocket(O ws, S uri) { super.onNewWebSocket(ws, uri); set(ws, 'timeout, timeout); S computerID = afterLastSlash(uri); if (!possibleComputerID(computerID)) computerID = "?"; wsToState.put(ws, nu(State, +computerID)); cI.gotConnection(computerID); rst.trigger(); } void onWebSocketClosed(O ws) { super.onWebSocketClosed(ws); State s = wsToState.get(ws); if (s != null) cI.lostConnection(s.computerID); rst.trigger(); } void onWebSocketMessage(O ws, S s) {} }; } html { ret "Use WebSocket: " + subBot_myWebSocketURI(); } svoid sendNumber(O ws) { State s = wsToState.get(ws); if (s != null && theNumber != s.countSeen) { s.countSeen = theNumber; print("Sending number to " + s.computerID + ": " + theNumber); call(ws, 'send, str(theNumber)); } } svoid update { print("OS Instances update"); if (webSocketManager.isEmpty()) ret; int value = cI.value(); //if (value == theNumber) ret; theNumber = value; for (O ws : webSocketManager.webSockets()) pcall { sendNumber(ws); } print("OS Instances update done"); }