Expand description
A Server and Client with parrallel read/write with async_std library.
Internal data will be automatically serialized and de-serialized by the trait KnetTransform.
It is advised to use the internal derive macro DeriveKnet on enum.
Here is a basic example:
§Server/Client
The Server and the Client has the run that allows you to start asynchronously.
It return (Self, Receiver)
You can read the Event with the receiver in a loop.
§Example
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);
}
}
}There is small difference between them :
Server::write_allandClient::writehave similar prototype but just difference name. It allow you to send theTover the network.Server::writeis the same as above but have aIdparamater to precise on which connection you want to send the data.- The
Receiverfrom theServerhave a wrapperEvent.
§DeriveKnet
The derive macro allow you to automatically implement the trait KnetTransform.
§Example
#[derive(DeriveKnet, Debug, PartialEq, Clone, Copy)]
enum Data {
Byte(u8),
Integer(i32),
Char(char),
Float(f64),
}Structs§
Enums§
- Event
- The wrapper event for the server. It allow you to know when there is a new connection, a data or and drop receive by the server