added loop to listener

This commit is contained in:
Mika 2024-10-13 22:43:23 +02:00
parent 38a0f4d189
commit 87416e5af9

View file

@ -53,11 +53,17 @@ async fn main() -> std::io::Result<()> {
loop {
if let Ok((mut stream, _)) = listener.accept().await {
let mut buffer = vec![0; 1024];
if let Ok(size) = stream.read(&mut buffer).await {
buffer.truncate(size);
if let Ok((data, _)) = Data::from_bytes((&buffer, 0)) {
println!("Received: {:?}", data);
// Process the data or save it to the database
loop {
if let Ok(size) = stream.read(&mut buffer).await {
buffer.truncate(size);
if let Ok((data, _)) = Data::from_bytes((&buffer, 0)) {
println!("Received: {:?}", data);
// Process the data or save it to the database
} else {
println!("Failed to parse data");
}
} else {
break;
}
}
}