How to use the mdns/cache.get function in mdns

To help you get started, we’ve selected a few mdns examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kinoma / kinomajs / xs6 / extensions / mdns / mdns_resolver.js View on Github external
function _resolv(name, cb)
{
	let message = require.weak("mdns/message");

	// shortcut for localhost
	if (name == "localhost")
		name = "127.0.0.1";
	// check if the name is already in the dot notation
	if (Socket.aton(name))
		return name;
	// check if the name is in the cache
	let res = cache.get(name);
	if (res && res.addr)
		return res.addr;
	// ask the name server or broadcast to the local network
	if (name.endsWith(".local."))
		name = name.slice(0, -1);
	let multicast = name.endsWith(".local");
	let q = message.query(0, name, multicast);		// not using the ID
	let s = new MSocket({multicast: multicast, data: q, onData: pkt => {
		let addr;
		if (pkt) {
			let res = message.parse(pkt);
			if (res.rcode == 0) {
				for (let i = 0, ans = res.ans; i < ans.length; i++) {
					if (ans[i].addr) {
						addr = ans[i].addr;
						break;