3 use crate::schema::hello_world::HelloWorld;
5 use connect::tcp::TcpListener;
6 use connect::{SinkExt, StreamExt};
11 async fn main() -> anyhow::Result<()> {
14 // Get ip address from cmd line args
15 let args: Vec<String> = env::args().collect();
17 let ip_address = match args.get(1) {
20 error!("Need to pass IP address to bind to as command line argument");
26 let mut server = TcpListener::bind(ip_address).await?;
28 // handle server connections
29 // wait for a connection to come in and be accepted
30 while let Some(mut conn) = server.next().await {
31 info!("Handling connection from {}", conn.peer_addr());
33 task::spawn(async move {
34 while let Some(msg) = conn.reader().next().await {
35 if msg.is::<HelloWorld>() {
36 if let Ok(Some(contents)) = msg.unpack::<HelloWorld>() {
38 "Received a message \"{}\" from {}",
39 contents.get_message(),
46 .expect("Could not send message back to source connection");
47 info!("Sent message back to original sender");
50 error!("Received a message of unknown type")