Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor() {
super();
this.finder = dgram.createSocket('udp4');
var _this = this;
this.finder.on('message', function(message, remote) {
_this.foundServer(message, remote);
}).on('close', function() {
// console.log('finder closed');
});
}
var GraphiteUDP = module.exports = function GraphiteUDP(opts)
{
assert(opts && _.isObject(opts), 'you must pass an options object');
assert(opts.host && _.isString(opts.host), 'you must pass a hostname in the `host` option');
assert(opts.port && _.isNumber(opts.port), 'you must pass a `port` option');
stream.Writable.call(this, { objectMode: true });
if (!opts.batchDelay || !_.isNumber(opts.batchDelay)) opts.batchDelay = 5000; // in ms
this.socket = dgram.createSocket('udp4');
this.socket.on('error', this.onError.bind(this));
this.options = opts;
this.log = bole('graphite ' + opts.host + ':' + opts.port);
this.log.info('graphite output configured @ ' + opts.host + ':' + opts.port);
};
util.inherits(GraphiteUDP, stream.Writable);
function StatsdBackend(startupTime, config, events) {
var self = this;
this.config = config.statsdBackend;
this.max_payload_length = (this.config.mtu || 1500) - 8; // 8 = UDP header length.
this.socket = dgram.createSocket('udp4');
this.metric_lines = {};
events.on('flush', function(time_stamp, metrics) { self.flush(time_stamp, metrics); });
}
seneca.ready(function() {
var message = new Buffer(service);
var client = dgram.createSocket('udp4');
client.send(message, 0, message.length, 11404, 'localhost', function (err, bytes) {
client.close();
});
seneca.add({role: service, cmd: 'suicide'}, function (err, cb) {
seneca.close(function (err) {
process.exit(err ? 1: 0);
});
cb();
});
});
it('should also close the TCP server', function(done) {
sandbox.spy(nodeCoap, 'createServer');
let tcpServer = createProxy(digs);
let coapServer = getCoAPServer();
sandbox.restore(nodeCoap, 'createServer');
expect(coapServer).to.be.instanceof(nodeCoap.createServer);
let stub = sandbox.stub();
tcpServer.on('close', stub);
coapServer._sock = require('dgram').createSocket('udp4');
coapServer.close();
process.nextTick(function() {
expect(stub).to.have.been.calledOnce;
done();
});
});
});
it('should imply a default port', function (done) {
server2 = dgram.createSocket('udp4')
server2.bind(5683, function () {
request('coap://localhost').end()
})
server2.on('message', function (msg, rsinfo) {
ackBack(msg, rsinfo)
done()
})
})
var dgram = require('dgram');
var message = new Buffer("Hello from UDP Client!");
var client = dgram.createSocket("udp4");
console.log("Client sending: " + message);
client.send(message, 0, message.length,
12345, "localhost", function (err, bytes) {
client.close();
});
constructor(settings) {
super();
this._settings = settings;
this._server = createSocket({type: 'udp4', reuseAddr: true});
this._server.on('message', (msg, rinfo) => this.emit('message', msg, rinfo.address));
this._server.on('error', (err) => this.emit('message', err));
}
return new Promise(resolve => {
try {
this.server = dgram.createSocket("udp4");
this.registerListeners();
this.server.bind(this.port, SERVER_ADDRESS, () => {
resolve();
});
} catch (err) {
console.error("error", err);
}
});
}
var dgram = require('dgram');
var server = dgram.createSocket("udp4");
server.on ("message", function(msg, rinfo) {
console.log("Message: " + msg + " от " + rinfo.address + ":"+ rinfo.port);
});
server.bind(8124);