lib/zonar.js
function listen(next) {

        listenSocket = dgram.createSocket({ type: 'udp4', reuseAddr: true });

        listenSocket.on('message', function(payload, rinfo) {
            var message = parseMessage(payload, rinfo);
            if (message) {
                if (message.id != id) {
                    if (message.status == "ONE") {
                        updateNodeList(message);
                    } else if (message.name != listenNameIdentifier && message.status == "NAMETAKEN") {
                        stop(function() {
                            //throw new Error('name already taken "' + name + '"');
                            self.emit("error", {cause: "Name already taken"});
                        });
                    }
                } else {
                    //self.emit('error', id + " already exists in network");
                    throw new Error(id + ' already exits in network');
                    stop();
                }
            }
        });

        listenSocket.bind(function(err) {
            var info = listenSocket.address();
            self.port = info.port;
            next(err);
        });

    }
function listen(next) {

        listenSocket = dgram.createSocket({ type: 'udp4', reuseAddr: true });

        listenSocket.on('message', function(payload, rinfo) {
            var message = parseMessage(payload, rinfo);
            if (message) {
                if (message.id != id) {
                    if (message.status == "ONE") {
                        updateNodeList(message);
                    } else if (message.name != listenNameIdentifier && message.status == "NAMETAKEN") {
                        stop(function() {
                            //throw new Error('name already taken "' + name + '"');
                            self.emit("error", {cause: "Name already taken"});
                        });
                    }
                } else {
                    //self.emit('error', id + " already exists in network");
                    throw new Error(id + ' already exits in network');
                    stop();
                }
            }
        });

        listenSocket.bind(function(err) {
            var info = listenSocket.address();
            self.port = info.port;
            next(err);
        });

    }
function listen ( next ) { listenSocket = dgram . createSocket ( { type : 'udp4' , reuseAddr : true } ) ; listenSocket . on ( 'message' , function ( payload , rinfo ) { var message = parseMessage ( payload , rinfo ) ; if ( message ) { if ( message . id != id ) { if ( message . status == "ONE" ) { updateNodeList ( message ) ; } else if ( message . name != listenNameIdentifier && message . status == "NAMETAKEN" ) { stop ( function ( ) { //throw new Error('name already taken "' + name + '"'); self . emit ( "error" , { cause : "Name already taken" } ) ; } ) ; } } else { //self.emit('error', id + " already exists in network"); throw new Error ( id + ' already exits in network' ) ; stop ( ) ; } } } ) ; listenSocket . bind ( function ( err ) { var info = listenSocket . address ( ) ; self . port = info . port ; next ( err ) ; } ) ; }
Listen for incoming single messages
Listen for incoming single messages