Created
June 30, 2019 19:19
-
-
Save msarchet/6a2a8818fa9e2ea0327db5d165998cab to your computer and use it in GitHub Desktop.
A Dexplexer example for working with orca on multiple port
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 dgram = require('dgram') | |
const PortMaps = require('./portmaps.json') | |
this.server = dgram.createSocket('udp4') | |
this.listener = dgram.createSocket('udp4') | |
this.listener.on('message', (msg, rinfo) => { | |
let parts = `${msg}`.split("M") | |
let maps = parts[0].split("") | |
let message = parts[1] | |
maps.forEach(map => { | |
if (PortMaps[map]) { | |
let port = PortMaps[map] | |
console.log('sending to', port, message) | |
this.server.send(Buffer.from(`${message}`), port, '127.0.0.1', (err) => err && console.warn(err)) | |
} | |
}) | |
}) | |
this.listener.on('listening', () => { | |
const address = this.listener.address() | |
console.log(`listening for UDP:\n ${address.address}:${address.port}`) | |
}) | |
this.listener.on('error', (err) => { | |
console.log(`Server error:\n ${err.stack}`) | |
this.listener.close() | |
}) | |
this.listener.bind(process.env.PORT || 49161) |
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
{ | |
"1": "49162", | |
"2": "49163" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment