From 2d94539fc5f02a973b51018397aa4dc3832d1b81 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Sun, 25 Feb 2024 08:32:57 -0800 Subject: [PATCH] Documentation for Uptime --- examples/C/src/browser-ui/README.md | 4 ++++ examples/C/src/browser-ui/Uptime.lf | 23 ++++++----------------- examples/C/src/browser-ui/img/Uptime.png | Bin 0 -> 11130 bytes 3 files changed, 10 insertions(+), 17 deletions(-) create mode 100644 examples/C/src/browser-ui/img/Uptime.png diff --git a/examples/C/src/browser-ui/README.md b/examples/C/src/browser-ui/README.md index 5311ff19..f41ae0b3 100644 --- a/examples/C/src/browser-ui/README.md +++ b/examples/C/src/browser-ui/README.md @@ -16,4 +16,8 @@ The UI runs in the browser and connects to the program via either HTTP or via a WebSocketString WebSocketString.lf: This version uses the simpler WebSocketServerString reactor, which is simpler in that it restricts the messages transported over the web socket to be of string types and it allows only one client to connect. + + Uptime + Uptime.lf: This version combines ServerUI with WebSocketServer to serve a web page and then feed it data continuously through a web socket. The application displays the total time that application has been running and updates this time once per second. + \ No newline at end of file diff --git a/examples/C/src/browser-ui/Uptime.lf b/examples/C/src/browser-ui/Uptime.lf index 6e23beae..ac873d99 100644 --- a/examples/C/src/browser-ui/Uptime.lf +++ b/examples/C/src/browser-ui/Uptime.lf @@ -1,6 +1,9 @@ /** - * FIXME. - * http://localhost:8080 + * This example combines `ServerUI` with `WebSocketServer`. The former starts a web server + * that listens for HTTP requests on port 8080 and serves the web page defined in `uptime.html`. + * That web page includes JavaScript that connects to a web socket on port 8000 that is provided + * by the `WebSocketServer` reactor. The resulting web page simply reports the total time that + * this program has been running. That time is updated on the web page once per second. * * @author Edward A. Lee */ @@ -14,9 +17,7 @@ import WebSocketServer from "../lib/WebSocketServer.lf" main reactor { timer seconds(0, 1s) - - state count: int = 0 - + s = new ServerUI(hostport = 8080, initial_file = "Uptime.html") w = new WebSocketServer() @@ -24,10 +25,6 @@ main reactor { lf_print("Point your browser to http://localhost:8080"); =} - reaction(s.initialized) {= - self->count++; // Count the number of connections. - =} - reaction(seconds) -> w.send {= instant_t uptime = lf_time_logical_elapsed(); // Truncate to the nearest second. @@ -42,12 +39,4 @@ main reactor { to_send->message = message; lf_set(w.send, to_send); =} - - reaction(w.connected) {= - if (w.connected->value.connected) { - lf_print("======== Connected a new client: %p", w.connected->value.wsi); - } else { - lf_print("======== Disconnected client: %p", w.connected->value.wsi); - } - =} } diff --git a/examples/C/src/browser-ui/img/Uptime.png b/examples/C/src/browser-ui/img/Uptime.png new file mode 100644 index 0000000000000000000000000000000000000000..073765fdd0a2b4f9023ccb1526c637bdb4c7e457 GIT binary patch literal 11130 zcmb`NF%yUx+^`J{g-Tf$dX!6^Fs9}jjS^m3O7+h?y zi3_?!lwFU%3rzTZCwlC(pt`P|4tK^W^5sm#+qR!=-T`5;WkdMSd|i= zr%CtEloD~tua-sYI2J@r$A0CYz6Os`b;EbsLFuzG1DB?0)j<>InlzmAy|M!BtG2z; zoY+As)9P3DdET*r-$+Kju(O>F*Yu&$LPwat|ArYJk};gPCGvJGb2C9~4SXxQ{^4vh znmG~Ns~!P(qU%l2de9ZCzK{&*w7K`3k>hPFSM4jhp!4ayDR0 z7^lKPZKqoU&`N7SY-0DVZR4l|E&M3gbAskBr{8-1wLQ1c85(G%!6Cw6Gy=sj zcqWM;!cI8hSCX78DG?vF^vPFr^+qK#q}LA}xuDY)v{OlBegDimTgv@+tcb{t*s(AY zV&EoaA4Y`C<)Y2r6>;!MxbUGEIOJOY4Qp^rXi}OZ!JRvvUZ&%f zV@VoW3{S^y(Xcxzd!Cp6pSil==C+;uKr(j;YD7(aAKsvWj!ar2!sW|2V3;rnV#dUN}C zXm*c0c@3wvop?WhMen}_0qIHOCtWrS(J!|i!ghwWVKR#H@4NiA&0qk6*{Wj3ZwP14_p^2%P4BC56OL{JhUvIbeF5i(d~K*?S~Tw&VVH*r0x?fkB+<`8&E4z@ylb|SOu0bxky^d_aI=q zqx2jXF=lE7{6J=K$B`P?@O<^fFr_p&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