wsclient

Crates.iowsclient
lib.rswsclient
version0.1.2
sourcesrc
created_at2023-04-17 11:51:11.898754
updated_at2023-04-17 13:06:00.427707
descriptionA websocket client using tokio-tungstenite for easy dev
homepage
repositoryhttps://github.com/aseuler/wsclient.git
max_upload_size
id841402
size31,733
(aseuler)

documentation

README

Usage

use ctrlc;
use std::env;
use wsclient;

#[derive(Default)]
struct DataListener {}

impl wsclient::Handler for DataListener {
    fn process(&self, data: String) {
        println!("{:?}", data);
    }
}

#[tokio::main]
pub async fn main() {
    let url = env::args()
        .nth(1)
        .unwrap_or_else(|| panic!("this program requires at least one argument"));
    let listener = DataListener::default();
    wsclient::WsClient::new()
        .start(url, Box::new(listener))
        .await;

    use std::sync::mpsc::channel;
    let (tx, rx) = channel();
    ctrlc::set_handler(move || tx.send(()).expect("Could not send signal on channel."))
        .expect("Error setting Ctrl-C handler");
    rx.recv().expect("Could not receive from channel.");
    println!("Ctrl-C and exiting...");
    std::process::exit(0);
}

Commit count: 16

cargo fmt