Reputation: 1431
I have to connect and send a message to a server. It needs the Message Length and the manual states:
message length: fixed size (4 bytes)
How do you get a fixed length size in javascript/node.js? Suppose the message is: "Hello, hand shake."
Upvotes: 0
Views: 118
Reputation: 11052
Use a buffer:
var buffer = new Buffer(4, 'hex');
buffer.write('aabbaaaa'); // 10101010 10111011 10101010 10101010
docs:
http://nodejs.org/api/buffer.html#buffer_buffer
useful nodejitsu article:
http://docs.nodejitsu.com/articles/advanced/buffers/how-to-use-buffers
Upvotes: 1