Accept JSON from mwtchahrd.

This commit is contained in:
mattbk
2025-10-05 20:37:22 -05:00
parent 97f6a4bdb9
commit 0698deee41
3 changed files with 107 additions and 2 deletions

View File

@@ -1,13 +1,14 @@
use std::net::UdpSocket; // UDP server
use rusqlite::{params, Connection, Result}; // Database operations and result handling
use std::time::{SystemTime, UNIX_EPOCH};
use serde_json::{Value};
fn main() -> std::io::Result<()> {
// Set up db and make sure it works
let _ = create_database();
let _ = insert_packet("foo");
//let _ = insert_packet("foo");
let socket_result: Result<UdpSocket, std::io::Error> = UdpSocket::bind("127.0.0.1:7878");
let socket: UdpSocket = match socket_result {
@@ -33,7 +34,14 @@ fn main() -> std::io::Result<()> {
String::from_utf8_lossy(&buffer[..bytes_received])
);
let _ = insert_packet(&String::from_utf8_lossy(&buffer[..bytes_received]));
let p_raw = &String::from_utf8_lossy(&buffer[..bytes_received]);
// look for type code in JSON here, only insert if data
let p: Value = serde_json::from_str(p_raw)?;
if p["type"] != "status" {
let _ = insert_packet(p_raw);
}
// Echo the data back to the client
socket.send_to(&buffer[..bytes_received], src_addr)?;