1 // tattlekey: A one-key UDP keyboard
2 // Copyright (C) 2023 Scott Worley <scottworley@scottworley.com>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
17 use std::net::UdpSocket;
19 const MESSAGE_SIZE: usize = 12;
22 let socket = UdpSocket::bind("0.0.0.0:29803").expect("couldn't bind to address");
24 let mut buf = [0; MESSAGE_SIZE];
25 match socket.recv_from(&mut buf) {
26 Err(e) => eprintln!("Didn't receive data: {e}"),
27 Ok((number_of_bytes, src_addr)) => {
28 let filled_buf = &mut buf[..number_of_bytes];
29 if number_of_bytes != MESSAGE_SIZE {
30 eprintln!("Ignoring short message ({number_of_bytes}) from {src_addr}");
33 println!("Got packet from {src_addr}: {filled_buf:?}");