Crates.io | async-io-helper |
lib.rs | async-io-helper |
version | 0.1.0 |
source | src |
created_at | 2021-03-21 06:16:01.837339 |
updated_at | 2021-03-21 06:16:01.837339 |
description | boxed async io for client/server. |
homepage | https://github.com/tyrchen/async-io-helper |
repository | https://github.com/tyrchen/async-io-helper |
max_upload_size | |
id | 371592 |
size | 20,759 |
Boxed async IO for tokio client/server.
Usage:
Server:
let listener = TcpListener::bind(addr).await.unwrap();
tokio::spawn(async move {
let (stream, _) = listener.accept().await.unwrap();
let io = ServerIo::new(stream);
info!("server: accepted: {:?}", io.remote_addr());
let (mut reader, mut writer) = split(io);
let mut buf = [0; 12];
reader.read_exact(&mut buf).await.unwrap();
info!("server: got data: {:?}", buf);
writer.write_all(&buf).await.unwrap();
info!("server: flush the data out");
});
Client:
let mut stream = TcpStream::connect(addr).await.unwrap();
info!("client: conn established");
stream.write_all(msg).await.unwrap();
info!("client: send data");
let (mut reader, _writer) = split(stream);
reader.read_exact(buf).await.unwrap();
info!("client: read echoed data");
async-io-helper
is distributed under the terms of MIT.
See LICENSE for details.
Copyright 2021 Tyr Chen