Skip to content

async-osc

Async Rust library for the Open Sound Control (OSC) protocol

Crates.io versionDownloaddocs.rs docs

This crate implements an async interface on the OSC 1.0 protocol. It uses async-std for async networking and rosc for OSC encoding and decoding.

Installation

$ cargo add async-osc

Example

use async_osc::{prelude::*,Error,OscPacket,OscSocket,OscType,Result};use async_std::stream::StreamExt;#[async_std::main]asyncfnmain() -> Result<()>{letmut socket = OscSocket::bind("localhost:5050").await?;// Open a second socket to send a test message.
async_std::task::spawn(asyncmove{let socket = OscSocket::bind("localhost:0").await?;
socket.connect("localhost:5050").await?;
socket
.send(("/volume",(0.9f32,"foo".to_string()))).await?;Ok::<(),Error>(())});// Listen for incoming packets on the first socket.whileletSome(packet) = socket.next().await{let(packet, peer_addr) = packet?;eprintln!("Receive from {}: {:?}", peer_addr, packet);match packet {OscPacket::Bundle(_) => {}OscPacket::Message(message) => match&message.as_tuple(){("/volume",&[OscType::Float(vol),OscType::String(ref s)]) => {eprintln!("Set volume: {} {}", vol, s);}
_ => {}},}}Ok(())}

Safety

This crate uses #![deny(unsafe_code)] to ensure everything is implemented in 100% Safe Rust.

Contributing

Want to join us? Check out our "Contributing" guide and take a look at some of these issues:

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Async Rust library for the Open Sound Control (OSC) protocol

Topics

Resources

Code of conduct

Contributing

Stars

21 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages