//! The minimal OmniVox client: connect, talk, done. //! //! Companion to `omnivox-server`. Sends `Hello`, prints the echo, then //! exchanges two more notes and stops. use omnivox::ConnectionStatus; use serde::{Deserialize, Serialize}; use std::time::Duration; #[derive(Serialize, Deserialize, Debug)] enum ChatMsg { Hello, Note(String), } #[tokio::main] async fn main() -> Result<(), Box> { tracing_subscriber::fmt() .with_target(false) .without_time() .init(); let client = omnivox::client::() // Same password + salt as the server — they derive the same PSK. .password("SecurePassword123", b"static-demo-salt") .on_data(|msg, _ctx| match msg { ChatMsg::Hello => tracing::info!("server greeted us unprompted?"), ChatMsg::Note(text) => tracing::info!("server note: {text}"), }) // Fires on Connected, ConnectionFailed, and later NotConnected. .on_state(|ctx| { tracing::info!("state: {:?}", ctx.status()); if ctx.status() == ConnectionStatus::ConnectionFailed { tracing::error!("is the server running? (cargo run --example omnivox-server)"); } }) .connect("127.0.0.1", 8080) .await?; client.send(&ChatMsg::Hello).await; tokio::time::sleep(Duration::from_millis(300)).await; client.send(&ChatMsg::Note("first note".into())).await; client.send(&ChatMsg::Note("second note".into())).await; tokio::time::sleep(Duration::from_millis(300)).await; client.stop().await; Ok(()) }