-
holy. freaking. crap. I didn't know there was an argument to the connect callback - the sample code I found didn't have an arg. And yes, putting them inside the callback and using 'socket' made it work. I am now seeing the 0xEF packets being sent. Solved all of the confusion.
As for the UDP code, it does work, but I don't claim to have written it correctly, I'll change it to match the link you provided.
So thanks a million for the corrections!
https://www.espruino.com/Reference#l_net_connect
You must place the
.on
functions inside of the connect callback using the returned socket, e.g.:How and if your UDP code really works is also questionable, it should be similar:
https://www.espruino.com/Reference#l_dgram_createSocket
While the example on https://www.espruino.com/Internet is exactly as you did it just doesn't correspond to the documentation.
And I'd change
let tcpClient = require('net');
toconst NET = require('net');
. It's just a shortcut to the net library, not a tcpClient.