title: Error writing to nodejs socket (TypeError: Invalid data, chunk must be a string or buffer, not object)
body: <p>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</p>
  
  <pre><code>var abuff = new ArrayBuffer(8 + encodedBuffer.length);
  console.log(Buffer.from(abuff));
  socket.write(Buffer.from(abuff));
  </code></pre>
  
  <p>TypeError: Invalid data, chunk must be a string or buffer, not object
  The console.log shows the following:</p>
  
  <pre><code>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]
  </code></pre>
  
  <p>and not Buffer?</p>
  
  <p>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"</p>
  
  <p>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.</p>
  
  <p>To solve I used IPC to send request from the renderer to the main process and let the main process manage the socket communication.</p>