mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-22 23:30:29 +01:00
c9c507aece
Basically a copy/paste of whats in warp. Example usage: ```rust use tower_web::{prelude::*, ws::{ws, WebSocket}}; let app = route("/ws", ws(handle_socket)); async fn handle_socket(mut socket: WebSocket) { while let Some(msg) = socket.recv().await { let msg = msg.unwrap(); socket.send(msg).await.unwrap(); } } ```
9 lines
258 B
JavaScript
9 lines
258 B
JavaScript
const socket = new WebSocket('ws://localhost:3000/ws');
|
|
|
|
socket.addEventListener('open', function (event) {
|
|
socket.send('Hello Server!');
|
|
});
|
|
|
|
socket.addEventListener('message', function (event) {
|
|
console.log('Message from server ', event.data);
|
|
});
|