Open Sound Control

"Open Sound Control (Osc) is an open, transport-independent, message-based protocol developed for communication among computers, sound synthesizers, and other multimedia devices." (from http://opensoundcontrol.org/spec-1_0)

There are a number of Osc implementations, including another in C#, but I decided to roll my own and make it freely available. This implementation sits atop the .NET 4.5 Framework and uses TCP or UDP as the transport protocol. It includes support for Osc Messages and Bundles, and supports the following payload data types: Int32, Int64, Float, Double, String, Blob (byte array), Osc TimeTag, ASCII character, boolean, Nil, Infinitum, and RGBA color.

The OscServer class is at the heart of the system, and includes support for unicast, broadcast, and multicast. As OSC packets, bundles, and messages are received corresponding events are fired. Additionally, the system will (optionally) filter Osc address patterns that the user registers.

The package includes simple client and server examples in both C# and Visual Basic.NET.

4/27/2013 Update

I’ve begun hosting this project on bitbucket.org. I’m leaving this page here for the time being, but please refer to the Bitbucket repository for code updates and issue tracking.

 

Archive

Release Notes (version 2.0)

  • Updated to .NET 4.0 Framework and Visual Studio 2010.
  • Overhauled TCP transport and corrected message framing.
  • Added support for Osc TimeTag, ASCII character, boolean, Nil, Infinitum, and RGBA color.
  • Events now properly raised for nested Osc bundles and messages.
  • Much improved documentation.
  • Simplified and separated out functionality in the Bespoke.Common library.
  • Changed the default expected byte order (endianness) back to Big endian (as per the OSC specification).
  • Improved demo applications.
  • General refactoring.

Release Notes (version 1.7.0)

  • Fixed TcpServer spinning in its listener thread.
  • Changed the default expected byte order (endianness) from Big to Little endian.
  • Added OscPacket.LittleEndianByteOrder property to allow users to change the expected byte order.
  • Fixed asynchronous, inline data handling within TcpServer. Default data handling behavior for TCP messages is now asynchronous (previously synchronous).
  • Added explicit project configurations for x64 platforms and have included pre-compiled x64 binaries (along with x86 binaries).

Release Notes (version 1.6.0.0)

  • Added UDP port reuse (multi-cast only). This allows for multiple simultaneous OscServer instances (or other services) bound to the same port.
  • Added OscServer.ConsumeParseExceptions (enabled by default) which suppresses parsing exceptions caused by malformed OSC packets. Disable this option to allow such exceptions to bubble up through the OscServer.

Previous Revisions

97 Comments so far

  1. Paul on March 24th, 2011

    Derek, I read a forum post about OSControl that I think describes the problem you’re having. I posted a reply to https://sourceforge.net/tracker/index.php?func=detail&aid=2984389&group_id=295990&atid=1249412?feedback=openid_error.

    Please let me know if this addresses your issue.

    Paul

  2. Derek on March 24th, 2011

    Thanks for the quick response to the issue. I’ll take a look at changing the target environment of the library tonight. Not the most advanced programmer but I should be able to figure it out.. Thanks for all your work.. This is great stuff your doing!!

  3. […] Bespoke OSC Library (.NET) […]

  4. ???? » Blog Archive on April 3rd, 2011

    […] Open Sound Control Library for.NET v1.6?BespokeSoftware??? .NET??(C#?VB)?OSC?????????????? http://www.bespokesoftware.org/wordpress/?page_id=69 […]

  5. Mazvydas on April 11th, 2011

    Hello, I am trying to communicate my iphone (with TouchOSC application) to my pc (using your example VB.net client application). I changed the ServerAddress to iphone’s IP on the local network and also the ServerPort to the same one as iphone uses. However the client does not seem to get signals from the iphone. What may be the problem? Maybe I’ve forgot to add/change something in the code?

    Thanks.

  6. Paul on April 11th, 2011

    Hello Mazvydas,

    I’ve posted a reply to your question on the Forums at http://www.bespokesoftware.org/wordpress/?page_id=141/open-sound-control-library/iphone-to-bespoke-osc-using-touchosc/.

    Paul

  7. […] Open Sound Control […]

  8. Andrea Canciani on July 15th, 2011

    The “Online Documentation” link http://www.bespokesoftware.org/OSC/1.7.0.0/doc results in a “403 Permission Denied” error.

  9. Paul on July 15th, 2011

    Thanks for the heads up Andrea. It’s fixed.

    Paul

  10. Luke on July 17th, 2011

    Out of interest, what might be required to make this run on Linux?

  11. Paul on July 18th, 2011

    Hello Luke,

    I’ve posted a response to your question under the Forums section at http://www.bespokesoftware.org/wordpress/?page_id=141/open-sound-control-library/bespoke-osc-library-for-linux/.

    Paul

  12. […] Open Sound Control […]

  13. Luke on July 21st, 2011

    Wow!
    Haven’t tested it myself yet, but… great, thanks :-)

  14. David on November 22nd, 2011

    Thanks for the library. Horrible c# examples though!

  15. Robert on January 7th, 2012

    I have encountered a problem with the TCP version. In TcpServer.OnDataReceived, when mTotalBytesReceived > mMessageLength an assertion is invalidated. I’m not sure why you assume that mTotalBytesReceived always will be equal to or less than mMessageLength, since it might as well be more (which should be fully valid), in which case you should remove the message and then save the extra data for the next message?

  16. Paul on January 8th, 2012
  17. Robert on January 9th, 2012

    Since I need to be logged in and cannot register account at that forum I will reply here.

    I’m with you all the way but to “mTotalBytesReceived <= mMessageLength". Since TCP does not in anyway guarantee chunk length you can receive more data than mMessageLength (which is valid), e.g. recevied bytes could contain the end of the current message and the beginning of the next. As you are doing now you are discarding any extra data (beginning of the next message), when that should be prepended to the next received bytes.

  18. Paul on January 9th, 2012

    Hello Robert,

    I’ve made a post about why I’ve disabled Forum account creation — I’ve been inundated with forum spam. If you’d like an account I’d be happy to create one for you.

    To your statement. If you don’t feel the implementation is correct, you’re welcome to change it.

    Paul

  19. Robert on January 9th, 2012

    Please create an account for me. I might play around with a bit the library.

  20. Peter on January 16th, 2012

    Thanks for making the code available. It’s a shame it doesn’t compile.

    I’m using Visual Studio Professional with .NET 3.5, trying to use the C# version http://www.bespokesoftware.org/OSC/OscFramework_1.7.zip

    Error 1 The type or namespace name ‘Bespoke’ could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Administrator\Desktop\OscFramework_1\Source Code\Samples\OscDemo\CS\Client\Program.cs 5 7 Client
    Error 2 The type or namespace name ‘OscBundleReceivedEventArgs’ could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Administrator\Desktop\OscFramework_1\Source Code\Samples\OscDemo\CS\Client\Program.cs 27 62 Client
    Error 3 The type or namespace name ‘OscMessageReceivedEventArgs’ could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Administrator\Desktop\OscFramework_1\Source Code\Samples\OscDemo\CS\Client\Program.cs 32 57 Client
    Error 4 The type or namespace name ‘OscServer’ could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Administrator\Desktop\OscFramework_1\Source Code\Samples\OscDemo\CS\Client\Program.cs 52 18 Client
    Error 5 The type or namespace name ‘Bespoke’ could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Administrator\Desktop\OscFramework_1\Source Code\Samples\OscDemo\CS\Server\Program.cs 7 7 Server
    Error 6 The type or namespace name ‘OscBundle’ could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Administrator\Desktop\OscFramework_1\Source Code\Samples\OscDemo\CS\Server\Program.cs 84 24 Server
    Error 7 The type or namespace name ‘OscMessage’ could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Administrator\Desktop\OscFramework_1\Source Code\Samples\OscDemo\CS\Server\Program.cs 85 18 Server
    Error 8 The type or namespace name ‘OscClient’ could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Administrator\Desktop\OscFramework_1\Source Code\Samples\OscDemo\CS\Server\Program.cs 86 24 Server

    Plus a load of warnings. Sorry, but I’ll have to keep looking.
    Peter

  21. Peter on January 16th, 2012

    I take that back! The Mono version works fine. Thank you!

  22. Paul on January 17th, 2012

    Hello Peter,

    I’m glad you’ve got the Mono version working, but the Visual Studio version does work as well (same code, different environment). I suspect that your seeing an issue opening the project in Visual Studio 2010, though the projects are in VS 2008 format. VS 2010 doesn’t like that the OscDemo Client and Server projects target the .NET 2.0 Framework while the Bespoke.Common and Bespoke.Common.Osc projects target the .NET 3.5 Framework. VS 2008 is fine with it.

    To fix this issue, simply change the targets of the Client and Server projects to .NET 3.5 and you’ll be good to go.

    Paul

  23. […] C# wrapper, but it seemed to be rather complicated. Using Bespoke’s Open Sound Control (OSC) library, I started implementing my own C# TUIO server. It is still quite limited (only support external […]

  24. hc on March 2nd, 2012

    Hello,

    I am using this code to send the osc message to the application running on the same computer.

    public void sendMsg()
    {
    OscMessage msg = new OscMessage(_oscServer, _defaultPath);
    msg.Append((Int32)1);
    msg.Send(_oscServer);
    }

    However, I am getting this on the other application:

    16777216 :(int)

    I use the “other application” all the time, it doesn’t have any problem with OSC at all. Do you know what might be the problem? When I try the float value, I am always getting “0.00000” as well.

    Thanks in advance!

  25. Paul on March 2nd, 2012

    Hello hc,

    I suspect that your “other application” might be sending/receiving data in the reverse byte order (endianess) from the Bespoke OSC Library. This is easy to modify, just set the static OscPacket.LittleEndianByteOrder property from true to false.

    Paul

  26. hc on March 2nd, 2012

    I thought it is only applicable in an OSC Server. Now I add the code and it works fine. Thank you so much! Your library saved me from extra mile!

  27. […] Open Sound Control […]

  28. Valentin on July 13th, 2012

    What’s the difference between .net and mono versions?

  29. Paul on July 13th, 2012

    Mono is still .NET, but supports POSIX operating systems (e.g. Unix/Linux). The non-Mono release uses Microsoft Visual Studio.

    That’s the only difference, the codebase is identical.

    Paul

  30. Durval on March 1st, 2013

    Hi! Can you tell me how to change target IP and Port?

    Regards!

  31. Paul on March 1st, 2013

    Have a look at the demo app included with the library. It’s quite straight forward to transmit an OscPacket to a particular IPEndPoint, with minor differences between TCP and UDP transmission. With TCP you’ll “Connect” to the destination end point before calling “Send” and with UDP you’ll include the destination end point during “Send”.

    Paul

  32. Durval on March 2nd, 2013

    You’re right, yesterday i wasn’t looking carefully. A bit new to C#, so I am still a bit dumb :)

    Thank you for your answer!

  33. Bruce on March 20th, 2013

    Hello,
    I would like to use it for a Windows Phone 8 app, do you think it’s possible?
    thanks

  34. Paul on March 20th, 2013

    Hello Bruce,
    Yes, this should be possible but it’ll take some effort. As I understand it, Windows Phone 8 projects can’t reference non-Windows Phone 8 projects — so at a minimum you’d need to port the existing libraries to that platform. I can’t predict how much work that might be, but it’s nonzero.

    In particular, the Bespoke.Common.Osc library will need be to be ported, and it relies on a number of classes/enumerations within Bespoke.Common. I doubt the Osc-specific classes will cause much grief, but the network-related code within Bespoke.Common could pose problems.

    This is something I would ordinarily like to do, but I’m swamped at the moment and don’t see any free clock cycles in my schedule for the next couple of months.

    Paul

  35. Bruce on March 22nd, 2013

    Hello Paul,
    I am currently creating a WP8 project and I have added your libraries. I got 65 errors, but I’m confident to fix it all! I’ll let you know and will share the source when it’s fixed.

  36. Bruce on March 23rd, 2013

    Yes! it works fine, I managed to control Resolume with my windows phone 8.

  37. Paul on March 23rd, 2013

    Good deal. Glad you’ve found the library useful.

    Paul

  38. Bob on April 2nd, 2013

    Hello Paul,
    I am doing a kinect project and found your mono version library helpful for transmitting Messages. I used TCP Transport but the problem is that I cannot send the message too frequently. I did a test in Local Network. The result is that when message frame rate is greater than 20 Hz, a noticeable delay occurs. Am I writing some wrong codes as below?
    while (true)
    {
    Thread.Sleep(1000/framerate);
    OscMessage message = new OscMessage(sourceEndPoint, “/test/framerate”);
    message.Append(DateTime.Now.ToString());
    message.Client = mOscClient;
    message.Send();
    }

    Really appreciate for your help!

    Bob

  39. Andy on April 24th, 2013

    Hi Paul!

    I try to write a little vb.net application to remotely control a Behringer X32. Therefore I need to send messages from a certain port. But when I code something like that:

    Dim ipX32 As IPAddress = IPAddress.Parse(“10.7.181.78”)
    Dim ipepX32 As IPEndPoint = New IPEndPoint(ipX32, 10024)
    Dim ipepXControl As IPEndPoint = New IPEndPoint(IPAddress.Parse(“10.7.180.67”), 10023)

    Dim msg As New OscMessage(ipepX32, “/info V0.90 osc-server X32 1.13”)

    msg.Append(0)

    msg.Send(ipepXControl)

    the message is’nt sent from port 10024 (as I expected) but from a random port number (as it Looks like)

    Also when I try to set up a osc-server to listen on incoming messages I get the following error: “The index and the Count have to point to a position in the buffer. Parameter: bytes” (probably not translated correctly as I use a german version)

    Can you help me out?

    Thanks,

    Andy from Austria

  40. Paul on April 26th, 2013

    Hi Andy,

    To your question about specifying an outgoing port. As it happens, I’ve had another report recently, on this same issue and have added some code to address it. However, I haven’t published an update. I’m moving the code base to bitbucket (a github-style source control system). I’m actively working on that and expect to have an update later today. I’ll post back when it’s complete.

    I can’t speak to your second question. I have no error like that within the OSC library. Have you tried stepping through the code to find that error?

    Paul

  41. […] Open Sound Control […]

  42. Paul on April 27th, 2013

    Ok Andy, I’ve relocated the source code to bitbucket at https://bitbucket.org/pvarcholik/bespoke.osc. This is the latest revision and includes a new property for setting the UdpClient on all OscPackets. This allows you to send messages from a particular port by setting, for example, OscPacket.UdpClient = new UdpClient(10024);

    The updated demos (both C# and VB) include this call for the UdpTransmitter. Shout if you have any questions.

    Paul

  43. Louis Somers on August 3rd, 2013

    Thanks Paul, this is great!

    I’m going to try to get it to work on the .Net micro framework. I want to use a Netduino Plus 2 and have it remote control an X32 mixing console.

    Unfortunately there is no IPServer to inherit from in the micro framework, so it will still be quite some rework to use sockets. It seems like some other stuff is missing as well, but I don’t recognize it as part of the “standard” .Net framework library. For example Utility.SwapEndian(), and quite some Asserts. Are you using another lib? I downloaded the latest source from BitBucket.

    Thanks again for sharing this,
    Louis

  44. Paul on August 3rd, 2013

    Hello Louis,

    The library in question is Bespoke.Common. It’s a submodule for the Bespoke.Osc git repository on BitBucket. But, if you pulled down a .zip of the Bespoke.Osc repository (instead of cloning it) then it won’t recursively zip submodules.

    You can either download the Bespoke.Common repo separately from https://bitbucket.org/pvarcholik/bespoke.common. Or you can clone the Bespoke.Osc repo.

    Paul

  45. majid on November 26th, 2014

    Hi Paul,

    I used OSC for different type of platforms. I am using Unity, C and C#… I used OSC for Unity Unity, C Unity, C# C# and all works fine.
    These days I am working on a project and I need to send packets from C# to Unity. The C# sender can send packets to IP and port, but I can’t catch them in UnityOSC… I’m using OSC ver2 that I downloaded from here for sending. I think that the bundle format is different and I couldn’t fix that. Could you help me please? The Unity code receiver is here:

    void Update() {
    OSCHandler.Instance.UpdateLogs();
    servers = OSCHandler.Instance.Servers;

    foreach(KeyValuePair item in servers)
    {
    // If we have received at least one packet,
    // show the last received from the log in the Debug console

    if(item.Value.log.Count > 0)
    {
    int lastPacketIndex = item.Value.packets.Count – 1;
    item.Value.packets[lastPacketIndex].Data[0].ToString())); //First data value
    DebugConsole.Log (“Test” item.Value.packets[lastPacketIndex].Data[0]
    item.Value.packets[lastPacketIndex].Data[1]
    item.Value.packets[lastPacketIndex].Data[2]
    item.Value.packets[lastPacketIndex].Data[3]);
    }
    }
    }

  46. Paul on November 30th, 2014

    Hi majid,

    I’m afraid I can’t be of much direct assistance here. You’ll need to attach a debugger to Unity to see if any Osc packets are being received. The code you pasted isn’t likely the issue — it’s the underlying Unity OSC code and, as you stated, how it may be expecting OSC packets/bundles.

    As an aside, I’ve relocated this website to http://www.varcholik.org and there are Forums there that I respond to more quickly. Additionally, I recommend that you get the latest version of the Bespoke OSC Library from the repository at bitbucket.org.

    Paul

  47. Pedro Souza on August 26th, 2015

    Hello Paul,

    I want to thank you for the work.
    I have used this to send commands to Resolume.
    And thanks to Andy too, the comments here helped me.

    Very useful, thankssssss.

    Pedro from Brazil ||

Leave a reply