mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-04 17:31:29 +03:00
source code
This commit is contained in:
24
libs/parity-tokio-ipc/examples/client.rs
Normal file
24
libs/parity-tokio-ipc/examples/client.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use tokio::{self, prelude::*};
|
||||
use parity_tokio_ipc::Endpoint;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let path = std::env::args().nth(1).expect("Run it with server path to connect as argument");
|
||||
|
||||
let mut client = Endpoint::connect(&path).await
|
||||
.expect("Failed to connect client.");
|
||||
|
||||
loop {
|
||||
let mut buf = [0u8; 4];
|
||||
println!("SEND: PING");
|
||||
client.write_all(b"ping").await.expect("Unable to write message to client");
|
||||
client.read_exact(&mut buf[..]).await.expect("Unable to read buffer");
|
||||
if let Ok("pong") = std::str::from_utf8(&buf[..]) {
|
||||
println!("RECEIVED: PONG");
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
tokio::time::delay_for(std::time::Duration::from_secs(2)).await;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user