1

Good afternoon dear community,

I am working on a networking project where I receive data though UDP socket from a software called VDMX, and trying to parse the above-mentioned data types from the buffer.

In my node.js app, I receive values with the following socket client with no issue:

const dgram = require('dgram');
const server = dgram.createSocket('udp4');

server.on('error', (err) => {
  console.log(`server error:\n${err.stack}`);
  server.close();
});

server.on('message', (msg, rinfo) => {
  console.log(msg.toString());
});

server.on('listening', () => {
  const address = server.address();
  console.log(`server listening ${address.address}:${address.port}`);
});

server.bind(1235);

However the data retrieved from the software, I am not sure how to parse the necessary part from the data sent as string/buffer.

In every data sent, there is a prefix information of OSC info in the data sent like '/lux' by default. When I chose different data types, here is what I receive in my Node.js console:

If I choose float:

/lux,fB�F�
/lux,fB��
/lux,fB�ɘ
/lux,fB��

If I choose double:

/lux,d@L ��ϑL
/lux,d@L��S�
�|�x,d@K�f
/lux,d@K�Y�)�

If I choose integer 64-bit:

/lux,h1
/lux,h0
/lux,h/
/lux,h.

I would highly appreciate if you could guide me how to get the values from these buffers. Thank you very much in advance!

Uğur Kaya
  • 2,287
  • 3
  • 15
  • 23

1 Answers1

0

use msg.readDoubleLE(offset), msg.readFloat32LE(offset) and similar functions

https://nodejs.org/dist/latest-v10.x/docs/api/buffer.html#buffer_buf_readdoublele_offset

Andrey Sidorov
  • 24,905
  • 4
  • 62
  • 75
  • Hello Andrey, thanks a lot! Could you also guide me on what would be the most precise way to detect the offset? I am quite new to binary data and if I would be working with strings, I would basically just do split(indexOf(‘,’) +1) after comma. What is the convenient way to safely extract necessary part of the binary data in this case? Thanks a lot in advance again :) – Uğur Kaya Oct 23 '18 at 07:12
  • depends on your binary data, in your case I'd try `msg.readDoubleLE(5)` for double, looks like there is fixed 5 byte prefix common to all messages – Andrey Sidorov Oct 23 '18 at 07:18