//! tests/tcp_server.rs use ugly_smart_lib::{net_pub::spawn_and_log_error, smart_pub::StdArc, INetCallBack, INetwork}; use crate::helper::init_log; #[tokio::test] async fn tcp_server_test() { init_log(); struct MyServer {} impl INetCallBack> for MyServer { fn data_callback( self: ugly_smart_lib::smart_pub::StdArc, _data: Vec, _handle: String, _serv_type: ugly_smart_lib::net_pub::ServiceType, ) { } fn state_callback( self: ugly_smart_lib::smart_pub::StdArc, // &mut self, _handle: String, _state: ugly_smart_lib::net_pub::EConnectionState>, _serv_type: ugly_smart_lib::net_pub::ServiceType, ) { } } let my_server = StdArc::new(MyServer {}); let params = ugly_smart_lib::STcpServerParams { connection_addr: "127.0.0.1:8868".into(), call_back: Box::new(my_server), extra_params: "127.0.0.1:8868".into(), }; let server = ugly_smart_lib::smart_pub::StdArc::new(ugly_smart_lib::tcp_server::CTcpServer::new(params)); spawn_and_log_error(server.clone().start()); tokio::time::sleep(std::time::Duration::from_secs(10)).await; spawn_and_log_error(server.stop()); tokio::time::sleep(std::time::Duration::from_secs(1)).await; }