diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-09-17 12:44:48 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-09-17 12:44:48 +0800 |
| commit | 15832a893383a850c9d032ab1620661b0121f247 (patch) | |
| tree | 036356f9fefd7d4ca7ad97d893aad0c632910efc | |
| parent | bdaab12e6ece9e1c1a0f444ccd890ba47b49789f (diff) | |
Update examples
| -rw-r--r-- | crates/utils/tcp_connection/tcp_connection_test/Cargo.toml | 4 | ||||
| -rw-r--r-- | crates/utils/tcp_connection/tcp_connection_test/src/example_handle.rs | 21 |
2 files changed, 17 insertions, 8 deletions
diff --git a/crates/utils/tcp_connection/tcp_connection_test/Cargo.toml b/crates/utils/tcp_connection/tcp_connection_test/Cargo.toml index 54065ad..e4cba71 100644 --- a/crates/utils/tcp_connection/tcp_connection_test/Cargo.toml +++ b/crates/utils/tcp_connection/tcp_connection_test/Cargo.toml @@ -4,5 +4,5 @@ edition = "2024" version.workspace = true [dependencies] -tcp_connection = { path="../../tcp_connection" } -tokio = { version = "1.46.1", features = ["full"] }
\ No newline at end of file +tcp_connection = { path = "../../tcp_connection" } +tokio = { version = "1.46.1", features = ["full"] } diff --git a/crates/utils/tcp_connection/tcp_connection_test/src/example_handle.rs b/crates/utils/tcp_connection/tcp_connection_test/src/example_handle.rs index 2c84bd1..1f02133 100644 --- a/crates/utils/tcp_connection/tcp_connection_test/src/example_handle.rs +++ b/crates/utils/tcp_connection/tcp_connection_test/src/example_handle.rs @@ -7,10 +7,15 @@ pub(crate) struct ExampleClientHandle; impl ClientHandle<ExampleServerHandle> for ExampleClientHandle { fn process( - instance: ConnectionInstance, + mut instance: ConnectionInstance, ) -> impl std::future::Future<Output = ()> + Send + Sync { - let _ = instance; - async {} + async move { + let _ = instance.write_text("Hello, World!").await; + let Ok(result) = instance.read_text(512 as u32).await else { + return; + }; + println!("Received: `{}`", result); + } } } @@ -18,9 +23,13 @@ pub(crate) struct ExampleServerHandle; impl ServerHandle<ExampleClientHandle> for ExampleServerHandle { fn process( - instance: ConnectionInstance, + mut instance: ConnectionInstance, ) -> impl std::future::Future<Output = ()> + Send + Sync { - let _ = instance; - async {} + async move { + let Ok(_) = instance.read_text(512 as u32).await else { + return; + }; + let _ = instance.write_text("Hello!").await; + } } } |
