1use serde::{Deserialize, Serialize};
2use session_rs::{Method, session::Session};
3
4#[derive(Debug, Serialize, Deserialize)]
5struct Data;
6
7impl Method for Data {
8 const NAME: &'static str = "data";
9 type Request = String;
10 type Response = String;
11 type Error = String;
12}
13
14#[tokio::main(flavor = "current_thread")]
15async fn main() -> session_rs::Result<()> {
16 let session = Session::connect("127.0.0.1:8080", "/").await?;
17
18 session.start_receiver();
19
20 println!(
21 "Hi: {:?}",
22 session
23 .request::<Data>("Hello from client".to_string())
24 .await?
25 );
26
27 println!(
28 "Invalid data response: {:?}",
29 session
30 .request::<Data>("invalid_data".to_string())
31 .await?
32 );
33
34 tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await;
35
36 session.close().await?;
37 Ok(())
38}