Skip to content

Instantly share code, notes, and snippets.

@yavorski
Created April 17, 2016 11:07
Show Gist options
  • Save yavorski/71c74ad78fb89d868f4b52e2f842556d to your computer and use it in GitHub Desktop.
Save yavorski/71c74ad78fb89d868f4b52e2f842556d to your computer and use it in GitHub Desktop.
'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