Created
March 18, 2020 08:09
-
-
Save Xstoudi/6ac8265aea1fea04799c1650a0cc94aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const dgram = require('dgram'); | |
const server = dgram.createSocket('udp4'); | |
server.on('error', (err) => { | |
console.log(`server error:\n${err.stack}`); | |
server.close(); | |
}); | |
server.on('message', (msg, rinfo) => { | |
console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`); | |
}); | |
server.on('listening', () => { | |
const address = server.address(); | |
console.log(`server listening ${address.address}:${address.port}`); | |
}); | |
server.bind(8080, '0.0.0.0'); | |
const socket = dgram.createSocket('udp4'); | |
socket.connect(8080, '127.0.0.1', () => { | |
const oldPush = Array.prototype.push; | |
Array.prototype.push = function() { | |
Array.prototype.push = oldPush; | |
Object.defineProperty(this, 0, { | |
get() { | |
throw new Error('boom'); | |
}, | |
}); | |
}; | |
socket.send([]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment