Reputation: 71
I'm trying to send a udp packet using the node.js dgram package from an electron app. The send method calls for a Buffer, Uint8Array, or string. I'm getting a type error when I try to use a Buffer or UintArray however. The exact error is: TypeError: First argument must be a buffer or a string.
I can see in the Node.js dgram code that it is checking for a buffer using !(buffer instanceof Buffer
. If I try using instanceof on the buffer in my code it just returns object as the type, while if I try 'Buffer.isBuffer()' it returns true. I've tried all the methods that node provides for creating buffers buffer with no results. Send does accept strings but then I am running into all sorts of issues with encoding, and that feels kinda of hacky.
It looks like electron is running node 7.4.0.
I see my options from here as:
Any ideas?
Upvotes: 2
Views: 5427
Reputation: 71
To get this to work I just had to point my global Buffer value to the node buffer module as so: const Buffer = window.require('buffer').Buffer
Upvotes: 5