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 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?
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"
For anyone seeing this type of problem - This code was in the "renderer" process of Electron, the problem was the Buffer object in the "renderer" did not create a Buffer object from Buffer.from.
To solve I used IPC to send request from the renderer to the main process and let the main process manage the socket communication.