Skip to content

Auto-discovery

The main purpose of the auto-discovery feature is to enable viewing the accessible devices on the network programmatically without any prior knowledge of the network addresses.


Catchbox uses mDNS protocol for device discovery. The protocol was chosen due to its widespread adoption and ease of use.

Attention

More complicated network structures, for example, devices placed on a different IP subnet will not be found by service discovery due to the design of the mDNS protocol.

The protocol has pre-existing implementations across many programming languages, usually, as packages, however documentation on how to implement it without an existing solution is freely available.

A simple implementation with node.js would look like this.

#!/usr/bin/env node
var mdns = require('mdns'), 
    listOfCbDevices = {};
 
var mdnsBrowser = mdns.createBrowser(mdns.udp('catchbox'));
 
mdnsBrowser.on('serviceUp', function(service) {
    // ignore duplicate ups
    if(listOfCbDevices[service.name]) return;
 
    listOfCbDevices[service.name] = {'addresses': service.addresses, 'port': service.port};
    var cnt = Object.keys(listOfCbDevices).length;
 
    console.log('Catchbox device "'+service.name+' up at '+service.addresses[0]+':'+service.port+', now '+cnt+' devices on the net');
});
 
console.log('listening for Catchbox devices on the net')
mdnsBrowser.start();

The code above is example code taken directly from the node_mdns GitHub page, with minimal modifications to suit our use case.

The above should return the following:

Catchbox device "CB-8466b8 up at 192.168.8.35:5353, now 1 devices on the net

This is enough information for you to connect to the device. Read more about it in Establishing a connection section.

Some implementations require you to provide the service type and the instance name of the device for discovery, they are _catchbox._udp.local. in a <instance name>.<service type> format.


If you wish to implement the feature in your system make sure you pick the best-fitting solution for your case, and, as said before, a pre-existing solution is likely available for many of the popular programming languages.