First echo server barebones for problem_04
This commit is contained in:
parent
f8841921ec
commit
f659022e8c
5 changed files with 37 additions and 0 deletions
2
problem_04/.gitignore
vendored
Normal file
2
problem_04/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
/target/
|
||||||
|
.idea
|
||||||
17
problem_04/Cargo.toml
Normal file
17
problem_04/Cargo.toml
Normal 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
0
problem_04/bin/client.rs
Normal file
15
problem_04/bin/server.rs
Normal file
15
problem_04/bin/server.rs
Normal 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
3
problem_04/src/lib.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue