[−][src]Module networking::asyncronous
asyncronous implementation of the tcp networking provided in this crate
Client Example
use networking::{asyncronous::{AsyncHost, AsyncRecv, AsyncNetworkHost}, test_config}; #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let (peer, config) = test_config(); let host = AsyncHost::client_only(&config).await.unwrap(); let mut stream = host.connect(peer).await.unwrap(); let mut buffer = Vec::new(); println!( "got {} bytes from server", stream.recv(&mut buffer).await.unwrap() ); let string = String::from_utf8(buffer).unwrap(); println!("got message: {} from server", string); Ok(()) }
Server Example
use networking::{ asyncronous::{AsyncHost, AsyncNetworkHost, AsyncSend}, test_config, ConnectionRequest, }; #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let (peer, config) = test_config(); let mut host = AsyncHost::from_host_config(&config).await.unwrap(); let mut msg = networking::random_string(43235).into_bytes(); // can also be done in while let Some(Ok(strm)) = host.incoming()?.await // this was better for the example though if let Some(Ok(strm)) = host.incoming()?.await { let mut stream = strm.verify(&peer)?; // make sure you got a connection from the correct peer println!("sending message hello world"); stream.send(b"hello world").await.unwrap(); } Ok(()) }
Modules
encryption |
Structs
AsyncHost | host object, artifice network implementation of TcpListener |
AsyncRequest | |
AsyncStream | networking implementation that uses TCP to send information over the network |
Incoming | used to listen for incoming connections |
Outgoing | used for constructing an outgoing tcp connection an owned implementation doesn't exist, because it would be unneeded code |
OwnedStreamRecv | owned version of StreamRecv |
OwnedStreamSend | owned version of StreamSend |
StreamRecv | borrowed half of async stream used for receiving data |
StreamSend | borrowed half of an async stream that can be used for sending data |
Traits
AsyncDataStream | currently only used as a marker, will implement more functionality in the future |
AsyncNetworkHost | shared behavior between SllpSocket, and AsyncHost |
AsyncRecv | trait for receiving network data |
AsyncSend | trait for sending data over the network |