X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=examples%2Ftls-client%2Fsrc%2Fmain.rs;h=b513a67bd6660567ba7149707a26173732b2e9f1;hb=d6746514ba62b577be68d4dc2dac0f02bb96d068;hp=6d57a35070407d7519267dfad2a5ca2e5fbd1393;hpb=3012c6c96b954d7867f039e51d1f5964c134356a;p=connect-rs.git diff --git a/examples/tls-client/src/main.rs b/examples/tls-client/src/main.rs index 6d57a35..b513a67 100644 --- a/examples/tls-client/src/main.rs +++ b/examples/tls-client/src/main.rs @@ -1,6 +1,10 @@ +mod schema; + +use crate::schema::hello_world::HelloWorld; +use connect::tls::rustls::ClientConfig; +use connect::{Connection, SinkExt, StreamExt}; use log::*; -use seam_channel::net::tls::rustls::ClientConfig; -use seam_channel::net::{StitchClient, StitchNetClient}; +use protobuf::well_known_types::Any; use std::env; #[async_std::main] @@ -22,22 +26,24 @@ async fn main() -> anyhow::Result<()> { .map_err(|_| std::io::Error::new(std::io::ErrorKind::InvalidInput, "invalid cert"))?; // create a client connection to the server - let dist_chan = StitchNetClient::tls_client(ip_addr, &domain, client_config.into())?; + let mut conn = Connection::tls_client(ip_addr, &domain, client_config.into())?; - // create a channel for String messages on the TCP connection - let (sender, receiver) = dist_chan.bounded::(Some(100)); + // send a message to the server + let raw_msg = String::from("Hello world"); + info!("Sending message: {}", raw_msg); - // alert the connection that you are ready to read and write messages - dist_chan.ready()?; + let mut msg = HelloWorld::new(); + msg.set_message(raw_msg); - // send a message to the server - let msg = String::from("Hello world"); - info!("Sending message: {}", msg); - sender.send(msg).await?; + conn.writer().send(msg).await?; // wait for the server to reply with an ack - if let Ok(msg) = receiver.recv().await { - info!("Received reply: {}", msg); + while let Some(reply) = conn.reader().next().await { + info!("Received message"); + + let msg: HelloWorld = Any::unpack(&reply)?.unwrap(); + + info!("Unpacked reply: {}", msg.get_message()); } Ok(())