First echo server barebones for problem_04

This commit is contained in:
Bastian Gruber 2023-05-01 08:02:04 +02:00
parent f8841921ec
commit f659022e8c
No known key found for this signature in database
GPG key ID: BE9F8C772B188CBF
5 changed files with 37 additions and 0 deletions

2
problem_04/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target/
.idea

17
problem_04/Cargo.toml Normal file
View file

@ -0,0 +1,17 @@
[package]
name = "problem_04"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "server"
path = "bin/server.rs"
[[bin]]
name = "client"
path = "bin/client.rs"
[dependencies]
tokio = { version = "1.14.0", features = ["full"] }
tracing = "0.1.37"
tracing-subscriber = "0.3.17"

0
problem_04/bin/client.rs Normal file
View file

15
problem_04/bin/server.rs Normal file
View file

@ -0,0 +1,15 @@
use std::io;
use tokio::net::UdpSocket;
#[tokio::main]
async fn main() -> io::Result<()> {
let sock = UdpSocket::bind("0.0.0.0:8080").await?;
let mut buf = [0; 1024];
loop {
let (len, addr) = sock.recv_from(&mut buf).await?;
println!("{:?} bytes received from {:?}", len, addr);
let len = sock.send_to(&buf[..len], addr).await?;
println!("{:?} bytes sent", len);
}
}

3
problem_04/src/lib.rs Normal file
View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}