-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
24 lines (21 loc) · 675 Bytes
/
main.rs
File metadata and controls
24 lines (21 loc) · 675 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use titanium::web;
use web::prelude::*;
#[titanium::main]
async fn main() -> web::Result<()> {
let mut app = web::new_server();
app.at("/")
.with(web::WebSocket::new(|_, mut stream| async move {
while let Some(Ok(web::Message::Text(input))) = stream.next().await {
println!("data: {}", &input);
stream
.send_string(input)
.await?;
}
Ok(())
}))
.get(web::root_page_endpoint);
web::serve_internals(&mut app);
web::serve_client_code(&mut app, include_str!("./client.js"));
app.listen("127.0.0.1:8080").await?;
Ok(())
}