Julio Biason
3 years ago
2 changed files with 27 additions and 2 deletions
@ -1,8 +1,16 @@
|
||||
[package] |
||||
name = "txtclient" |
||||
description = "A client that keeps listened to whatever the server is producing and shows on stdout" |
||||
version = "0.1.0" |
||||
edition = "2021" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
bincode = "1.3.3" |
||||
env_logger = "0.9.0" |
||||
log = "0.4.14" |
||||
serde = { version = "1.0.130", features = ["derive"] } |
||||
tokio = { version = "1.14.0", features = ["rt", "net", "macros", "io-util"] } |
||||
|
||||
shared = { path = "../shared" } |
||||
|
@ -1,3 +1,20 @@
|
||||
fn main() { |
||||
println!("Hello, world!"); |
||||
use tokio::io::AsyncReadExt; |
||||
use tokio::net::TcpStream; |
||||
|
||||
use shared::Message; |
||||
|
||||
#[tokio::main(flavor = "current_thread")] |
||||
async fn main() { |
||||
env_logger::init(); |
||||
|
||||
let mut stream = TcpStream::connect("127.0.0.1:4435") |
||||
.await |
||||
.expect("Failed to connect to server"); |
||||
loop { |
||||
let mut buffer = [0; 1024]; |
||||
let bytes = stream.read(&mut buffer).await.expect("Failed to read data"); |
||||
let decoded: Message = |
||||
bincode::deserialize(&buffer[..bytes]).expect("Failed to convert message"); |
||||
log::info!("Got {:?}", decoded); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue