9 unstable releases (3 breaking)

0.4.0 Apr 23, 2021
0.3.2 Jan 31, 2021
0.2.2 Jan 12, 2021
0.2.0 Dec 19, 2020
0.1.2 Nov 23, 2020

#269 in WebSocket

39 downloads per month
Used in lnkit

MIT license

18KB
382 lines

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.

Dependencies

~9–19MB
~270K SLoC