Skip to content

Commit

Permalink
Documentation for Uptime
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardalee committed Feb 25, 2024
1 parent 11f134b commit 2d94539
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
4 changes: 4 additions & 0 deletions examples/C/src/browser-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ The UI runs in the browser and connects to the program via either HTTP or via a
<td> <img src="img/WebSocketString.png" alt="WebSocketString" width="400">
<td> <a href="WebSocketString.lf">WebSocketString.lf</a>: 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.</td>
</tr>
<tr>
<td> <img src="img/Uptime.png" alt="Uptime" width="400">
<td> <a href="Uptime.lf"> Uptime.lf</a>: 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.</td>
</tr>
</table>
23 changes: 6 additions & 17 deletions examples/C/src/browser-ui/Uptime.lf
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -14,20 +17,14 @@ 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()

reaction(startup) {=
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.
Expand All @@ -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);
}
=}
}
Binary file added examples/C/src/browser-ui/img/Uptime.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2d94539

Please sign in to comment.