Accept JSON from mwtchahrd.
This commit is contained in:
12
src/main.rs
12
src/main.rs
@@ -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)?;
|
||||
|
Reference in New Issue
Block a user