stuff
This commit is contained in:
parent
02a692bf01
commit
d11b9a1bab
3 changed files with 64 additions and 4 deletions
|
@ -2,9 +2,29 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>MiniHTTP Test</title>
|
||||
<style>
|
||||
body {
|
||||
color: white;
|
||||
background-color: #151515;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
a {
|
||||
color: #79d3ff;
|
||||
}
|
||||
a:visited {
|
||||
color: #719bff;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
Websocket test
|
||||
<script src="./websocket.js"></script>
|
||||
<h1>Example website</h1>
|
||||
<div style="padding-left:20px;">
|
||||
<a href="./websocket">Websocket test</a><br>
|
||||
<a href="./custom/foo/bar">Custom route</a><br>
|
||||
<a href="./test">test.htm</a><br>
|
||||
<br>
|
||||
<a href="./subpath/foo">Foo</a><br>
|
||||
<a href="./subpath/bar">Bar</a><br>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
28
Example/www-static/websocket.htm
Normal file
28
Example/www-static/websocket.htm
Normal file
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>MiniHTTP Test</title>
|
||||
<style>
|
||||
body {
|
||||
color: white;
|
||||
background-color: #151515;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
#log {
|
||||
color: #afc3ff;
|
||||
background-color: #2a2d35;
|
||||
font-family: monospace,monospace;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
border: solid white 1px;
|
||||
width: fit-content;
|
||||
min-width: 300px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Websocket test</h1>
|
||||
<div id="log"></div>
|
||||
<script src="./websocket.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,10 +1,22 @@
|
|||
const ws = new WebSocket(`wss://${location.host}/`, "test");
|
||||
function log(text) {
|
||||
document.getElementById("log").innerText += text + "\n";
|
||||
}
|
||||
|
||||
log("Connecting");
|
||||
const ws = new WebSocket(`wss://${location.host}/`, "test");
|
||||
function send(text) {
|
||||
log(">> " + text);
|
||||
ws.send(text);
|
||||
}
|
||||
ws.onerror = (e) => {
|
||||
log("Error: " + e);
|
||||
throw e;
|
||||
};
|
||||
ws.onopen = (event) => {
|
||||
ws.send("Hello world");
|
||||
log("Connected");
|
||||
send("Hello world");
|
||||
};
|
||||
ws.onmessage = (event) => {
|
||||
log("<< " + event.data);
|
||||
console.log(event.data);
|
||||
};
|
Loading…
Reference in a new issue