Created
April 17, 2016 11:07
-
-
Save yavorski/71c74ad78fb89d868f4b52e2f842556d 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
'use strict'; | |
const os = require('os'); | |
const dgram = require('dgram'); | |
const server = dgram.createSocket('udp4'); | |
const sep = '\n' + Array(80).join('-') + '\n'; | |
console.log(sep, os.networkInterfaces(), sep); | |
server.on('error', err => { | |
console.log(`server error:\n${err.stack}`); | |
server.close(); | |
}); | |
server.on('message', (msg, rinfo) => { | |
console.log(`msg: ${msg}`); | |
console.log(`from: ${rinfo.address}:${rinfo.port}`); | |
console.log('length', msg.length); | |
console.log('=================================================='); | |
}); | |
server.on('listening', () => { | |
var address = server.address(); | |
console.log(sep, `server listening ${address.address}:${address.port}`, sep); | |
}); | |
const PORT = process.env.PORT || 33333; | |
server.bind(PORT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment