#event-handling #server #async #user #incoming #data

webchaussette

Fast, powerful, and easy-to-set-up WebSocket library

6 stable releases

1.3.3 Apr 25, 2024
1.2.1 Apr 25, 2024
1.1.1 Apr 24, 2024
1.0.0 Apr 23, 2024

#2 in #incoming

Download history 461/week @ 2024-04-20 31/week @ 2024-04-27

492 downloads per month

MIT license

26KB
641 lines

Webchaussette

Fast, powerful, and easy-to-set-up WebSocket library

Version Documentation License

Installation

To use this library, simply add it to your Cargo.toml :

[dependencies]
webchaussette = "1.0"
async-trait = "0.1"
tokio = "1"

Example

use webchaussette::server::{EventHandler, Public, Server, Types};

// Implement the field if you wish
struct Test;

#[async_trait::async_trait]
impl EventHandler for Test {
    // Read incoming user data
    async fn on_message(&self, public: &mut Public) {
        match &public.message {
            Types::String(val) => println!("{}", val),
            Types::Binary(val) => println!("{:?}", val),
        }
    }
    async fn on_close(&self) {
        println!("The user has left");
    }
}

#[tokio::main]
async fn main() {
    let mut server: Server = Server::new("0.0.0.0:8080").await;
    server.set_handler(Box::new(Test));
    server.run().await;
}

Documentation

Documentation is being processed !

Contribution

Contributions are welcome! Feel free to open issues or send pull requests.

License

This project is licensed under MIT. See the LICENSE file for more details

Dependencies

~4–11MB
~98K SLoC