5 releases

new 0.2.2 Jan 12, 2021
0.2.1 Jan 11, 2021
0.2.0 Dec 19, 2020
0.1.3 Dec 6, 2020
0.1.2 Nov 23, 2020

#22 in WebSocket

25 downloads per month

MIT license

16KB
331 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_all(Message::Text(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().await {
            println!("{:?}", event);
        }
    });
}

Simple duplex communication example. See examples folder for more examples.

Should Add

  • option to automatically close inactive connections
  • option to not accept connections depending on their address (dynamic deny list)

Dependencies

~4.5–6.5MB
~146K SLoC