Encoding message from .NET to udprecieve.

Tim Aviss's icon

Hi,
I really need to transmit JSON data packets from my .NET application to Max/msp and I'm having a lot of trouble.
After many hours of google searches I haven't found what I'm looking for.

Currently in my VB.NET application I have the following code:
"
Dim udpclient As New UdpClient()
Dim ip As New IPEndPoint(IPAddress.Broadcast, 5000)

Dim bytes As Byte() = Encoding.UTF32.GetBytes(JSON)
udpclient.Send(bytes, bytes.Length, ip)
"

In Max/MSP I have a udprecieve object set to port 5000. In the max console window I get the following error message:
"udprecieve . OSC expected type string. Dropping message for address {"

As you can see, on the end of that error message is the first symbol of my JSON string.
I really need to get the full JSON string into max so I can parse it and then map the data.

Please help,
Thank you

David Butler's icon

The udpreceive object in Max is badly named. It does not receive raw UDP bytes, it only receives messages formatted with the OSC protocol. Similarly udpsend formats all messages into the OSC protocol. This makes them easy to use for communicating between Max patches, but not suitable for communicating with external software unless that software supports OSC.

You need to format your UDP packets as OSC. There's a few .NET libraries to do this (https://www.nuget.org/packages/Rug.Osc/ for example, although I haven't tried this one). Alternatively you could install the sadam library (https://cycling74.com/tools/the-sadam-library/#.VpjUM-iLSbg) which contains Max objects allowing receiving of raw UDP bytes.

Tim Aviss's icon

Thank you so much! Rug.osc worked perfectly and simply.
I have previousy tried to install the sadam library but found it needlessly complicated with crucial files missing in my native Max 7.1 64-bit installation eventually giving up due to multiple problems.

Anyway,
Thanks again, that's just what I needed.