Last active
May 8, 2020 20:01
-
-
Save cjdenio/93b7ea3be2c68710f40b0a5adb5ed0de to your computer and use it in GitHub Desktop.
This file contains 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
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