Crate async_osc[][src]

Async library for the Open Sound Control (OSC) protocol

Examples

use async_std::stream::StreamExt;
use async_osc::{prelude::*, OscSocket, OscPacket, OscType, Error, Result};

let mut socket = OscSocket::bind("localhost:5050").await?;

// Open a second socket to send a test message.
async_std::task::spawn(async move {
    let socket = OscSocket::bind("localhost:0").await?;
    socket.connect("localhost:5050").await?;
    socket.send(("/volume", (0.9f32,))).await?;
    Ok::<(), Error>(())
});

// Listen for incoming packets on the first socket.
while let Some(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)]) => {
                eprintln!("Set volume: {}", vol);
                // Do something with the received data.
                // Here, just quit the doctest.
                assert_eq!(vol, 0.9f32);
                return Ok(())
            }
            _ => {}
        },
    }
}
// tbi

Re-exports

pub use crate::rosc::*;

Modules

prelude

Prelude with extensions to rosc types.

rosc

Re-export the main OSC types from the rosc crate.

Structs

OscSender

A sender to send messages over an OSC socket.

OscSocket

A UDP socket to send and receive OSC messages.

Enums

Error

Error type for OSC operations.

Type Definitions

Result

Result type for OSC operations.