Skip to content

Instantly share code, notes, and snippets.

@cjdenio
Last active May 8, 2020 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjdenio/93b7ea3be2c68710f40b0a5adb5ed0de to your computer and use it in GitHub Desktop.
Save cjdenio/93b7ea3be2c68710f40b0a5adb5ed0de to your computer and use it in GitHub Desktop.
const CONFIG = {
sendPort: 8181,
receivePort: 1234
}
var dgram = require('dgram')
var sendSocket = dgram.createSocket('udp4')
var receiveSocket = dgram.createSocket('udp4')
receiveSocket.on('message', d => {
sendSocket.send(d, CONFIG.sendPort, '127.0.0.1', err => {
if (err) {
console.log("Something went wrong while forwarding a packet.")
}
else {
console.log(`Successfully forwarded a packet to local port ${CONFIG.sendPort}`)
}
})
})
receiveSocket.on('error', () => {
console.log("Something went wrong :( You may need to change the receivePort in the config.")
})
receiveSocket.bind(CONFIG.receivePort)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment