Skip to content

Instantly share code, notes, and snippets.

@mafintosh
Created August 28, 2018 16:46
Show Gist options
  • Save mafintosh/80638eef2bcdde14b7f17d89225fb1e4 to your computer and use it in GitHub Desktop.
Save mafintosh/80638eef2bcdde14b7f17d89225fb1e4 to your computer and use it in GitHub Desktop.
const speedometer = require('speedometer')
const speed = speedometer()
setInterval(function () {
console.log(speed())
}, 1000)
const udp = chrome.sockets.udp
udp.create({}, function (res) {
const sid = res.socketId
udp.onReceive.addListener(function (res) {
speed(res.data.byteLength)
})
udp.bind(sid, '0.0.0.0', 9999, function () {
console.log('bound')
const buf = new ArrayBuffer(1000)
setInterval(loop, 5)
function loop () {
udp.send(sid, buf, '159.65.107.57', 10000, noop)
}
function noop () {}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment