rustzmq2 0.1.0

A native async Rust implementation of ZeroMQ
Documentation
// 14_smol_req_rep — same REQ/REP pattern as 01_*, but on the smol runtime.
//
// Build with:
//   cargo run --no-default-features \
//       --features "smol,all-transports" --example 14_smol_req_rep
use rustzmq2::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    smol::block_on(async {
        let mut server = rustzmq2::RepSocket::new();
        server.bind("tcp://127.0.0.1:5602").await?;

        let client_task = smol::spawn(async {
            let mut client = rustzmq2::ReqSocket::new();
            client.connect("tcp://127.0.0.1:5602").await.unwrap();
            for i in 0..3u32 {
                client.send(format!("ping {i}")).await.unwrap();
                let reply: String = client.recv().await.unwrap().try_into().unwrap();
                println!("client got: {reply}");
            }
        });

        for _ in 0..3 {
            let req: String = server.recv().await?.try_into()?;
            println!("server got: {req}");
            server.send(req.replace("ping", "pong")).await?;
        }

        client_task.await;
        Ok(())
    })
}