Using the UDPRECEIVE object with outside code [C#]
How should I encode data so that it can be recognized in Max without errors such as:
udpreceive: OSC packet size (30) not a multiple of 4 bytes: dropping
I am current encrypting a simple string message as follows [C#]:
string tempMessage = "Hello Max/MSP";
data = Encoding.ASCII.GetBytes(tempMessage);
The data variable is then sent to port 7400 where it is received by Max but then rejected as it is not a multiple of 4 bytes.
How can I rectify this problem, do I need some extra padding to make the message up to a multiple of 4 bytes, or is there something else that is missing, perhaps a different method of encoding?
Thank you.
You could try creating an array of characters
that is 32-bit aligned and see if it is accepted.
I have tried padding the message so that it is a multiple of 4 using the following code [C#]:
private byte[] PadMessage(string message)
{
byte zero = 0;
// Clear current list of bytes
bytes.Clear();
// Add the encoded message as bytes
bytes.AddRange(encoding.GetBytes(message));
// Pad the message so that its length is a multiple of 4
int padding = 4 - (bytes.Count % 4);
for (int i = 0; i < padding; i++)
{
bytes.Add(zero);
}
return bytes.ToArray();
}
The data is sent to Max and I now receive the following error:
udpreceive: OSC expected type string. Dropping message for address Hello Max/MSP
The string needs to encoded as bytes to be sent via UDP so why am I getting this error in Max?
in the past, i've used oscpack to send data to max over udp, from a c++ app. http://www.audiomulch.com/~rossb/code/oscpack/
however, it's implementation just uses the os send function, which takes a char * as the data to send.
no idea about c#, but maybe this helps.
Figured out a solution to using third-party apps with udpreceive ...
In Flash / AS3 I did the following (retyped so there could be typos):
var message:String = "Hello!";
var data:ByteArray = new ByteArray();
data.writeUTFBytes(message);
var pad:int = 4 - ( data.length % 4 );
for ( var i:int = 0; i < pad; i++ ) { data.writeByte(0); }
data.writeUTFBytes(",");
data.writeByte(0);
data.writeByte(0);
data.writeByte(0);
datagramSocket.send( data, 0, 0, targetIP, targetPort);