extern crate rosc; use rosc::OscPacket; use std::env; use std::net::{SocketAddrV4, UdpSocket}; use std::str::FromStr; fn main() { let args: Vec = env::args().collect(); let usage = format!("Usage {} IP:PORT", &args[0]); if args.len() < 2 { println!("{}", usage); ::std::process::exit(1) } let addr = match SocketAddrV4::from_str(&args[1]) { Ok(addr) => addr, Err(_) => panic!("{}", usage), }; let sock = UdpSocket::bind(addr).unwrap(); println!("Listening to {}", addr); let mut buf = [0u8; rosc::decoder::MTU]; loop { match sock.recv_from(&mut buf) { Ok((size, addr)) => { println!("Received packet with size {} from: {}", size, addr); let (_, packet) = rosc::decoder::decode_udp(&buf[..size]).unwrap(); handle_packet(packet); } Err(e) => { println!("Error receiving from socket: {}", e); break; } } } } fn handle_packet(packet: OscPacket) { match packet { OscPacket::Message(msg) => { println!("OSC address: {}", msg.addr); println!("OSC arguments: {:?}", msg.args); } OscPacket::Bundle(bundle) => { println!("OSC Bundle: {:?}", bundle); } } }