mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-05 19:00:32 -05:00
add .html files for SSE and websocket examples
This commit is contained in:
parent
fe9596f4fe
commit
78ded146ac
2 changed files with 46 additions and 0 deletions
21
examples/sse_demo.html
Normal file
21
examples/sse_demo.html
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
<!-- to be used with sse_server -p 8087 -->
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="https://unpkg.com/htmx.org@1.7.0"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
htmx.createEventSource = (url) => {
|
||||||
|
return new EventSource(url, {withCredentials:false});
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body hx-trigger="onload" hx-sse="connect:http://localhost:8087/clock">
|
||||||
|
<p>time:</p>
|
||||||
|
<div hx-sse="swap:tick" hx-swap="innerHtml"> </div>
|
||||||
|
<!-- <div hx-trigger="sse:tick" hx-get="/news"></div> -->
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
25
examples/ws_demo.html
Normal file
25
examples/ws_demo.html
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
<!-- to be used with echo_ws -p 8085 -->
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
console.log('hello')
|
||||||
|
|
||||||
|
const ws = new WebSocket('ws://localhost:8085/echo');
|
||||||
|
ws.onmessage = (msg) => console.log(`received: ${msg}`);
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
|
setInterval(() => {
|
||||||
|
const msg = `hello ${count++}`;
|
||||||
|
console.log(`send ${msg}`);
|
||||||
|
ws.send(msg);
|
||||||
|
}, 2000);
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
open console!
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Loading…
Add table
Reference in a new issue