Crates.io | paperplane |
lib.rs | paperplane |
version | 0.4.0 |
source | src |
created_at | 2020-11-23 22:30:57.161225 |
updated_at | 2021-04-23 16:12:08.018016 |
description | Async WebSocket library |
homepage | |
repository | https://gitlab.com/rasmusmerzin/paperplane |
max_upload_size | |
id | 315568 |
size | 59,472 |
use async_std::task;
use paperplane::tungstenite::Message;
use paperplane::Server;
use std::time;
fn main() {
let server = Server::new(10);
// Send count to all connected clients each second
{
let server = server.clone();
task::spawn(async move {
let mut count = 0usize;
loop {
task::sleep(time::Duration::from_secs(1)).await;
server.send(None, count.to_string()).await.ok();
count += 1;
}
});
}
// Print messages sent by clients
task::block_on(async {
server.listen("0.0.0.0:8000").await.unwrap();
while let Some(event) = server.next::<Message>().await {
println!("{:?}", event);
}
});
}
Simple duplex communication example. See examples folder for more examples.