3 use crate::schema::hello_world::HelloWorld;
4 use connect::{Connection, SinkExt, StreamExt};
6 use protobuf::well_known_types::Any;
10 async fn main() -> anyhow::Result<()> {
13 // Get ip address from cmd line args
14 let args: Vec<String> = env::args().collect();
15 let ip_address = match args.get(1) {
18 error!("Need to pass IP address to connect to as command line argument");
23 // create a client connection to the server
24 let mut conn = Connection::tcp_client(ip_address).await?;
26 // send a message to the server
27 let raw_msg = String::from("Hello world");
29 let mut msg = HelloWorld::new();
30 msg.set_message(raw_msg.clone());
32 conn.writer().send(msg).await?;
33 info!("Sent message: {}", raw_msg);
35 // wait for the server to reply with an ack
36 while let Some(reply) = conn.reader().next().await {
37 info!("Received message");
39 let msg: HelloWorld = Any::unpack(&reply)?.unwrap();
41 info!("Unpacked reply: {}", msg.get_message());