1use tipsy::{Endpoint, ServerId};
2use tokio::io::{AsyncReadExt, AsyncWriteExt};
3
4#[tokio::main]
5async fn main() {
6 let path = std::env::args()
7 .nth(1)
8 .expect("Run it with server path to connect as argument");
9
10 let mut client = Endpoint::connect(ServerId::new(path))
11 .await
12 .expect("Failed to connect client.");
13
14 loop {
15 let mut buf = [0u8; 4];
16 println!("SEND: PING");
17 client
18 .write_all(b"ping")
19 .await
20 .expect("Unable to write message to client");
21 client
22 .read_exact(&mut buf[..])
23 .await
24 .expect("Unable to read buffer");
25 if let Ok("pong") = std::str::from_utf8(&buf[..]) {
26 println!("RECEIVED: PONG");
27 } else {
28 break;
29 }
30
31 tokio::time::sleep(std::time::Duration::from_secs(2)).await;
32 }
33}