use spice_client::{SpiceClient, SpiceError};
use std::time::Duration;
use tokio::time::sleep;
#[tokio::main]
async fn main() -> Result<(), SpiceError> {
tracing_subscriber::fmt::init();
let host = std::env::var("SPICE_HOST").unwrap_or_else(|_| "localhost".to_string());
let port = std::env::var("SPICE_PORT")
.ok()
.and_then(|p| p.parse().ok())
.unwrap_or(5900);
println!("Connecting to SPICE server at {}:{}", host, port);
let mut client = SpiceClient::new(host, port);
match client.connect().await {
Ok(_) => println!("Connected successfully!"),
Err(e) => {
eprintln!("Failed to connect: {:?}", e);
return Err(e);
}
}
let client_handle = tokio::spawn(async move {
if let Err(e) = client.start_event_loop().await {
eprintln!("Event loop error: {:?}", e);
}
});
println!("Client is running. Press Ctrl+C to stop.");
tokio::select! {
_ = tokio::signal::ctrl_c() => {
println!("\nShutting down...");
}
_ = client_handle => {
println!("Client disconnected");
}
}
Ok(())
}