lib/core/discovery.js
function onServerMessage(message, rinfo) {

	var packet,
	    respond;

	alchemy.setStatus('multicast_messages', ++messages);

	try {
		packet = bson.deserialize(message);
	} catch(err) {
		log.warn('Received corrupt multicast message from ' + rinfo.address);
		return;
	}

	// Ignore packets that come from here
	if (packet.origin == alchemy.discovery_id) {
		return;
	}

	packet.remote = rinfo;

	if (packet.respond) {
		respond = function respond(data) {

			var response_packet = {
				type         : 'response',
				response_to  : packet.id,
				data         : data
			};

			submit(response_packet);
		};
	}

	// Emit it as a multicast event
	alchemy.emit('multicast', packet, respond, null);

	if (packet.response_to) {
		if (typeof callbacks[packet.response_to] === 'function') {
			callbacks[packet.response_to](packet.data, packet);
		}
	} else {
		// Emit it for multicast listeners only
		mevents.emit(packet.type, packet.data, packet, respond, null);
	}
}
function onServerMessage(message, rinfo) {

	var packet,
	    respond;

	alchemy.setStatus('multicast_messages', ++messages);

	try {
		packet = bson.deserialize(message);
	} catch(err) {
		log.warn('Received corrupt multicast message from ' + rinfo.address);
		return;
	}

	// Ignore packets that come from here
	if (packet.origin == alchemy.discovery_id) {
		return;
	}

	packet.remote = rinfo;

	if (packet.respond) {
		respond = function respond(data) {

			var response_packet = {
				type         : 'response',
				response_to  : packet.id,
				data         : data
			};

			submit(response_packet);
		};
	}

	// Emit it as a multicast event
	alchemy.emit('multicast', packet, respond, null);

	if (packet.response_to) {
		if (typeof callbacks[packet.response_to] === 'function') {
			callbacks[packet.response_to](packet.data, packet);
		}
	} else {
		// Emit it for multicast listeners only
		mevents.emit(packet.type, packet.data, packet, respond, null);
	}
}
function onServerMessage ( message , rinfo ) { var packet , respond ; alchemy . setStatus ( 'multicast_messages' , ++ messages ) ; try { packet = bson . deserialize ( message ) ; } catch ( err ) { log . warn ( 'Received corrupt multicast message from ' + rinfo . address ) ; return ; } // Ignore packets that come from here if ( packet . origin == alchemy . discovery_id ) { return ; } packet . remote = rinfo ; if ( packet . respond ) { respond = function respond ( data ) { var response_packet = { type : 'response' , response_to : packet . id , data : data } ; submit ( response_packet ) ; } ; } // Emit it as a multicast event alchemy . emit ( 'multicast' , packet , respond , null ) ; if ( packet . response_to ) { if ( typeof callbacks [ packet . response_to ] === 'function' ) { callbacks [ packet . response_to ] ( packet . data , packet ) ; } } else { // Emit it for multicast listeners only mevents . emit ( packet . type , packet . data , packet , respond , null ) ; } }
Listen for messages

@author   Jelle De Loecker   <jelle@develry.be>
@since    0.1.0
@version  0.4.3
Listen for messages