mr_socketio

Crates.iomr_socketio
lib.rsmr_socketio
version0.1.1
created_at2025-01-20 04:36:32.586833+00
updated_at2025-01-20 08:25:07.998515+00
descriptionA brief description of what your crate does
homepage
repositoryhttps://github.com/supaatwi/mr_socketio
max_upload_size
id1523561
size65,505
(supaatwi)

documentation

https://github.com/supaatwi/mr_socketio/blob/main/README.md

README

Mr socketio

Example usage (Client)

Add the following to your Cargo.toml file:

mr_socketio = "*"

Then you're able to run the following example code:

use std::sync::Arc;
use mr_socketio::client::SocketIOClient;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
 
let client = Arc::new(SocketIOClient::new("host"));

    println!("Starting connection...");
    client.on("chat", |data| {
        println!("Received message event: {:?}", data);
    }).await;

    // Connect in a separate task
    let connect_handle = {
        let client = client.clone();
        tokio::spawn(async move {
            client.connect().await
        })
    };


    println!("Wait a bit for the connection to establish");
    loop {
        tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
        if client.is_connected().await {
            break;
        }
    }

    // Emit the event
    println!("Emitting chat event...");
    client.emit("chat", json!({
        "say": "Hello Socket Client"
    })).await?;


    // Wait for the connection task to complete
    connect_handle.await??;

    Ok(())
}

Licence

MIT

Commit count: 4

cargo fmt