diff --git a/tests/socket-test/Cargo.toml b/tests/socket-test/Cargo.toml index af548ad..99286a8 100644 --- a/tests/socket-test/Cargo.toml +++ b/tests/socket-test/Cargo.toml @@ -12,3 +12,6 @@ rust_socketio = { path = "D:/githubs/rust-socketio/socketio", features = ["async serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.112" toml = "0.8.8" + +tracing = "0.1.40" +tracing-subscriber = { version = "0.3.18", features = ["time"] } diff --git a/tests/socket-test/src/main.rs b/tests/socket-test/src/main.rs index 4426e67..75f47fa 100644 --- a/tests/socket-test/src/main.rs +++ b/tests/socket-test/src/main.rs @@ -1,6 +1,12 @@ -use rust_socketio::{Payload, RawClient}; +use rust_socketio::{Payload, RawClient, Event}; fn main() { + + + tracing_subscriber::fmt() + .with_max_level(tracing::Level::DEBUG) + .init(); + // 从命令行读取配置文件路径 let args: Vec = std::env::args().collect(); if args.len() != 2 { @@ -19,17 +25,13 @@ fn main() { ); let socket = rust_socketio::ClientBuilder::new(url) - .on("connect", |args, _| { - println!("Connected: {:?}", args); + .transport_type(rust_socketio::TransportType::Websocket) + .on_any(|event: Event, payload: Payload, _: RawClient| { + println!("Received event: {:?} with payload: {:?}", event, payload); }) - .on("event", |args, _| { - println!("Event: {:?}", args); - }) - .on("disconnect", |args, _| { - println!("Disconnected: {:?}", args); - }) - .on("error", |args, _| { - println!("Error!!: {:?}", args); + .on("error", |err, _: RawClient| { + println!("Received error: {:?}", err); + // panic!("Error received from server {:?}", err); }) .connect() .unwrap(); @@ -46,7 +48,9 @@ fn main() { std::time::Duration::from_secs(10), request_callback, ); - println!("Request result: {:?}", res); + + let empty: Vec = vec![]; + socket.emit("request-cert", Payload::from(empty)).unwrap(); std::thread::sleep(std::time::Duration::from_secs(20)); }