I have 3 pieces of information that I need to send in a UDP packet, the userID (int), auth code (string) and the binary data.
How would I be able to send those items at once and be able to split them at the other end.
I've tried concat'ing three buffers with the information but can't figure a way to split them at the other end, as the UID and auth code will vary in length.
assuming that the following apply
packing
var BinaryData=/*Your binary data*/;
var bufToSend = new Buffer(3+100+BinaryData.length);
bufToSend.writeUInt32LE(INTEGER,0);
bufToSend.write(STRING,4,STRING.length,"ascii");
BinaryData.copy(bufToSend,105,0,BinaryData.length);
unpacking
var userID = bufFromUDP.readUInt32LE(0);
var authCode = bufFromUDP.slice(4,104);
var BinaryData = bufFromUDP.slice(105,bufFromUDP.length);
Also you can try adding a "separator" between fields. ex.
var sep = new Buffer(2);
sep.write(";",0,1,'ascii');
and when doing Buffer.concat([userID,sep,authCode,sep]);
after each field add the sep byte.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With