paperplane

Crates.iopaperplane
lib.rspaperplane
version0.4.0
sourcesrc
created_at2020-11-23 22:30:57.161225
updated_at2021-04-23 16:12:08.018016
descriptionAsync WebSocket library
homepage
repositoryhttps://gitlab.com/rasmusmerzin/paperplane
max_upload_size
id315568
size59,472
Emil Rasmus Merzin (rasmusmerzin)

documentation

README

logo
Paperplane

build license version documentation

WebSocket library which utilizes async-std, async-tungstenite & futures.

Example

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.

Commit count: 48

cargo fmt