A server and a client that can write and read data asynchronously to and from a T-type data derived by the knet-derive crate.
#[derive(DeriveKnet, Debug, Clone, Copy)]
enum Data {
Integer(i32),
Char(char)
}
Server::write_all(server.0.clone(), Data::Integer(32)).await?;
Server::write(server.0.clone(), Data::Integer(32), 0).await?;
Client::write_all(server.0.clone(), Data::Integer(32)).await?;
loop {
match receiver.try_next() {
Ok(Some(event)) => {
println!("Receive event<T> {:?} ", event);
}
Ok(None) => {
eprintln!("Connection is down");
break;
}
Err(e) => {
error!("Nothing receive from receiver", e);
}
}
}