send messages with own speed (20)

This commit is contained in:
Martin Brodbeck 2023-10-03 19:56:13 +02:00
parent 6017a6ca47
commit 4f714c1be1

View file

@ -6,6 +6,7 @@ use std::{
const MAX_CLIENTS: usize = 10; const MAX_CLIENTS: usize = 10;
const CLIENT_TIMEOUT: u32 = 300; const CLIENT_TIMEOUT: u32 = 300;
const MY_SPEED: u8 = 20;
#[derive(Hash, Eq, PartialEq, Debug, Clone)] #[derive(Hash, Eq, PartialEq, Debug, Clone)]
struct Client { struct Client {
@ -151,7 +152,6 @@ fn main() -> std::io::Result<()> {
time: Local::now(), time: Local::now(),
}; };
let speed = buf[1] >> 2; let speed = buf[1] >> 2;
println!("Speed: {speed} WPM");
let data = &buf[0..number_of_bytes]; let data = &buf[0..number_of_bytes];
@ -163,11 +163,11 @@ fn main() -> std::io::Result<()> {
if receivers.len() < MAX_CLIENTS { if receivers.len() < MAX_CLIENTS {
receivers.insert(client.clone()); receivers.insert(client.clone());
socket socket
.send_to(mopp(speed, b"hi").as_slice(), &client.name) .send_to(mopp(MY_SPEED, b"hi").as_slice(), &client.name)
.unwrap(); .unwrap();
} else { } else {
socket socket
.send_to(mopp(speed, b":qrl").as_slice(), &client.name) .send_to(mopp(MY_SPEED, b":qrl").as_slice(), &client.name)
.unwrap(); .unwrap();
} }
} else { } else {
@ -178,7 +178,7 @@ fn main() -> std::io::Result<()> {
for cl in &receivers { for cl in &receivers {
if cl.time + Duration::seconds(CLIENT_TIMEOUT as i64) < timestamp { if cl.time + Duration::seconds(CLIENT_TIMEOUT as i64) < timestamp {
socket socket
.send_to(mopp(speed, b":bye").as_slice(), &client.name) .send_to(mopp(MY_SPEED, b":bye").as_slice(), &client.name)
.unwrap(); .unwrap();
} }
} }