Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var assert = require('assert');
var net = require('net');
var dgram = require('dgram');
var EventEmitter = require('events').EventEmitter;
var util = require('util');
Expand Down Expand Up @@ -50,7 +51,12 @@ Server.prototype.listen = function listen(port, address, callback) {

var self = this;

this._socket = dgram.createSocket('udp6');
var ip_version = net.isIP(address);

if (!ip_version)
self.emit('error', new Error("Invalid IP address"));

this._socket = dgram.createSocket((ip_version == 4) ? 'udp4' : 'udp6');
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this logic to a constant / variable that sits higher up?
No sense to repeat it twice. After that happy to merge. :)

this._socket.once('listening', function () {
self.emit('listening');
if (typeof (callback) === 'function')
Expand All @@ -71,7 +77,7 @@ Server.prototype.listen = function listen(port, address, callback) {
};

var src = {
family: 'udp6',
family: ((ip_version == 4) ? 'udp4' : 'udp6'),
address: rinfo.address,
port: rinfo.port
};
Expand Down