Swiftpack.co - sammysmallman/OSCKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
sammysmallman/OSCKit 3.0.1
The OSCKit package provides the classes needed for your apps to communicate among computers, sound synthesizers, and other multimedia devices via OSC over an IP network.
⭐️ 53
🕓 2 weeks ago
iOS macOS tvOS
.package(url: "https://github.com/sammysmallman/OSCKit.git", from: "3.0.1")

“OSCKit”/

OSCKit

The OSCKit package provides the classes needed for your apps to communicate among computers, sound synthesizers, and other multimedia devices via OSC over an IP network.

Overview

Use the OSCKit package to create client or server objects. In its simplest form a client can send a packet, either a Message or Bundle to a server. A server, when listening, can receive these packets and action upon them. Depending on a client or server using either UDP or TCP as a transport, there are varying levels of fuctionality and delegate methods for you to take advantage of.

OSCKit implements all required argument types as specified in OSC 1.1.

Features

  • UDP and TCP Transport options
  • UDP Servers can join multicast groups
  • UDP Clients can broadcast packets
  • TCP Server with client management
  • TCP Stream Framing
  • OSC Bundles
  • OSC Timetags

Installation

Xcode 11+

Add the package dependency to your Xcode project using the following repository URL:

https://github.com/SammySmallman/OSCKit

Swift Package Manager

Add the package dependency to your Package.swift and depend on "OSCKit" in the necessary targets:

dependencies: [
    .package(url: "https://github.com/SammySmallman/OSCKit", .upToNextMajor(from: "3.0.1"))
]

App Sandbox Network Settings

  • Enable Incoming Connections (Required for OSCTcpClient, OSCTcpServer & OSCUdpServer)
  • Enable Outgoing Connections (Required for OSCTcpClient, OSCTcpServer & OSCUdpClient)

Quick Start

TCP Client

Step 1

Import OSCKit into your project

import OSCKit

Step 2

Create a client

let client = OSCTcpClient(host: "10.101.130.101",
                          port: 24601,
                          streamFraming: .SLIP,
                          delegate: self)

Step 3

Conform to the clients delegate protocol OSCTcpClientDelegate:

func client(_ client: OSCTcpClient,
            didConnectTo host: String,
            port: UInt16) {
    print("client did connect to \(host):\(port)")
}

func client(_ client: OSCTcpClient,
            didDisconnectWith error: Error?) {
    if let error = error {
       print("client did disconnect with error: \(error.localizedDescription)")
    } else {
       print("client did disconnect")
    }
}

func client(_ client: OSCTcpClient,
            didSendPacket packet: OSCPacket) {
    print("Client did send packet")
}
    
func client(_ client: OSCTcpClient,
            didReceivePacket packet: OSCPacket) {
    print("Client did receive packet")
}
    
func client(_ client: OSCTcpClient,
            didReadData data: Data,
            with error: Error) {
    print("Client did read data with error: \(error.localizedDescription)"
}

Step 4

Create an OSCPacket e.g. An OSC message:

do {
    let message = try OSCMessage(with: "/osc/kit", arguments: [1,
                                                               3.142,
                                                               "hello world!"])
} catch {
    print("Unable to create OSCMessage: \(error.localizedDescription)")
}

Step 5

Send the packet

client.send(message)
TCP Server

Step 1

Import OSCKit into your project

import OSCKit

Step 2

Create a client

let server = OSCTcpServer(port: 24601,
                          streamFraming: .SLIP,
                          delegate: self)

Step 3

Conform to the servers delegate protocol OSCTcpServerDelegate:

func server(_ server: OSCTcpServer,
            didConnectToClientWithHost host: String,
            port: UInt16) {
    print("Server did connect to client \(host):\(port)")
}

func server(_ server: OSCTcpServer,
            didDisconnectFromClientWithHost host: String,
            port: UInt16) {
    print("Server did disconnect from client \(host):\(port)")
}

func server(_ server: OSCTcpServer,
            didReceivePacket packet: OSCPacket,
            fromHost host: String,
            port: UInt16) {
    print("Server did receive packet")
}
    
func server(_ server: OSCTcpServer,
            didSendPacket packet: OSCPacket,
            toClientWithHost host: String,
            port: UInt16) {
    print("Server did send packet to \(host):\(port)")
}
    
func server(_ server: OSCTcpServer,
            socketDidCloseWithError error: Error?) {
    if let error = error {
       print("server did stop listening with error: \(error.localizedDescription)")
    } else {
       print("server did stop listening")
    }
}
    
func server(_ server: OSCTcpServer,
            didReadData data: Data,
            with error: Error) {
    print("Server did read data with error: \(error.localizedDescription)"
}

Step 4

Start listening for new connections and packets:

do {
    try server.startListening()
} catch {
    print(error.localizedDescription)
}
UDP Client

Step 1

Import OSCKit into your project

import OSCKit

Step 2

Create a client

let client = OSCUdpClient(host: "10.101.130.101",
                          port: 24601,
                          delegate: self)

Step 3

Conform to the clients delegate protocol OSCUdpClientDelegate:

func client(_ client: OSCUdpClient,
            didSendPacket packet: OSCPacket,
            fromHost host: String?,
            port: UInt16?) {
    print("client sent packet to \(client.host):\(client.port)")
}

func client(_ client: OSCUdpClient,
            didNotSendPacket packet: OSCPacket,
            fromHost host: String?,
            port: UInt16?,
            error: Error?) {
    print("client did not send packet to \(client.host):\(client.port)")
}

func client(_ client: OSCUdpClient,
            socketDidCloseWithError error: Error) {
    print("Client Error: \(error.localizedDescription)")
}

Step 4

Create an OSCPacket e.g. An OSC message:

do {
    let message = try OSCMessage(with: "/osc/kit", arguments: [1,
                                                               3.142,
                                                               "hello world!"])
} catch {
    print("Unable to create OSCMessage: \(error.localizedDescription)")
}

Step 5

Send the packet

client.send(message)
UDP Server

Step 1

Import OSCKit into your project

import OSCKit

Step 2

Create a client

let server = OSCUdpServer(port: 24601,
                          delegate: self)

Step 3

Conform to the servers delegate protocol OSCUdpServerDelegate:

func server(_ server: OSCUdpServer,
            didReceivePacket packet: OSCPacket,
            fromHost host: String,
            port: UInt16) {
    print("server did receive packet from \(host):\(port)")
}

func server(_ server: OSCUdpServer,
            socketDidCloseWithError error: Error?) {
    if let error = error {
       print("server did stop listening with error: \(error.localizedDescription)")
    } else {
       print("server did stop listening")
    }
}

func server(_ server: OSCUdpServer,
            didReadData data: Data,
            with error: Error) {
    print("Server did read data with error: \(error.localizedDescription)"
}

Step 4

Start listening for packets:

do {
    try server.startListening()
} catch {
    print(error.localizedDescription)
}

CoreOSC

OSCKit is supported by the infrastructural code provided by CoreOSC. For more detailed information pertaining to the OSC objects that OSCKit uses, such as Address Patterns, Messages and Bundles, please direct all queries to CoreOSC.

Authors

Sammy Smallman - Initial Work - SammySmallman

See also the list of contributors who participated in this project.

Acknowledgments

GitHub

link
Stars: 53
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Related Packages

Release Notes

v3.0.1
2 weeks ago

Depend on stable version of CoreOSC (1.0.0).

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics