Search code examples
stringarrayssmalltalkoscvisualworks

Converting Open Sound Control ByteArray into String in Smalltalk VisualWorks 7.9.1


I'm receiving UDP packets from a server ( exactly: Open Sound Control packets). i'm storing those packets in a ByteArray.

I want to convert this ByteArray into String so i can exploit the data received. I tried a lot of conversion but each time i'm having non readable charachters.

Here is the code :

| server peerAddr |
server := SocketAccessor newUDPserverAtPort: 3333.
peerAddr := IPSocketAddress new.
buffer := ByteArray new: 1024.
[ server readWait.
server receiveFrom: peerAddr buffer: buffer.

Transcript show: (buffer asString) ; cr ; flush. ] repeat.

I also tried the following conversion but in vain:

buffer asByteString.
buffer asStringEncoding:#UTF8.
buffer asStringEncoding:#UTF16.
buffer  asString.
buffer  asBase64String.
buffer  asFourByteString
buffer withEncoding: #ASCII

Here is the string output : enter image description here

Any help?

Additional info: The received data is open sound control data so it has a specific formatting, that's why it's diplayed like that, i need to parse ints, floats, strings, whitin a specific bytearray indexs. Does anyone recomand a package that offer those possibilities ?

Thx in advance.


Solution

  • You probably can borrow a lot of the code for Squeak's OSC package: http://opensoundcontrol.org/implementation/squeak-osc