mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-23 00:00:15 +02:00
Updated websocket example to improve clarity and to be more distinct from chat example (#1637)
Co-authored-by: David Pedersen <[email protected]>
This commit is contained in:
co-authored by
David Pedersen
parent
d11af167ca
commit
8d92902c8e
@@ -7,3 +7,19 @@ socket.addEventListener('open', function (event) {
|
||||
socket.addEventListener('message', function (event) {
|
||||
console.log('Message from server ', event.data);
|
||||
});
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
const obj = { hello: "world" };
|
||||
const blob = new Blob([JSON.stringify(obj, null, 2)], {
|
||||
type: "application/json",
|
||||
});
|
||||
console.log("Sending blob over websocket");
|
||||
socket.send(blob);
|
||||
}, 1000);
|
||||
|
||||
setTimeout(() => {
|
||||
socket.send('About done here...');
|
||||
console.log("Sending close over websocket");
|
||||
socket.close(3000, "Crash and Burn!");
|
||||
}, 3000);
|
||||
Reference in New Issue
Block a user