error writing binary data to TCP socket.

72 views
Skip to first unread message

Stephen James

unread,
Jan 3, 2018, 11:06:10 AM1/3/18
to nodejs

Using electron I am trying to write out some bytes on a TCP socket. I am using Buffer.from to convert to buffer before calling write, but am still getting the above error. I have simplified it down to just creating an empty ArrayBuffer and calling Buffer.from


var abuff = new ArrayBuffer(8 + encodedBuffer.length);
console.log(Buffer.from(abuff));
socket.write(Buffer.from(abuff));


TypeError: Invalid data, chunk must be a string or buffer, not object at Socket.write (net.js:667:11)


The console.log shows the following:

Uint8Array(51) [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

and not Buffer?


Why would Buffer.from not create a Buffer?


Versions in electron: 

ares:"1.10.1-DEV" 

atom-shell:"1.7.9" 

chrome:"58.0.3029.110" 

electron:"1.7.9" 

http_parser:"2.7.0" 

modules:"54" 

node:"7.9.0" 

openssl:"1.0.2k" 

uv:"1.11.0" 

v8:"5.8.283.38" 

zlib:"1.2.11"

Matt Sergeant

unread,
Jan 7, 2018, 11:33:19 AM1/7/18
to nod...@googlegroups.com
This has been fixed since. I don't know when. I have Node 9.3 and it produces a Buffer.

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/33bc035f-8074-4cc8-8d14-b0603570db7a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages