1 use connect::{ConnectDatagram, Connection, SinkExt, StreamExt};
6 async fn main() -> anyhow::Result<()> {
9 // Get ip address from cmd line args
10 let args: Vec<String> = env::args().collect();
11 let ip_address = match args.get(1) {
14 error!("Need to pass IP address to connect to as command line argument");
19 // create a client connection to the server
20 let mut conn = Connection::tcp_client(ip_address).await?;
22 // send a message to the server
23 let msg = String::from("Hello world");
24 info!("Sending message: {}", msg);
26 let envelope = ConnectDatagram::with_tag(65535, msg.into_bytes())?;
27 conn.writer().send(envelope).await?;
29 // wait for the server to reply with an ack
30 if let Some(reply) = conn.reader().next().await {
31 let data = reply.data().to_vec();
32 let msg = String::from_utf8(data)?;
34 info!("Received message: {}", msg);