Graphics.UsingDNSServiceDiscovery - lordmundi/wikidoctest GitHub Wiki

Using DNS Service Discovery

« Import Lightwave models into EDGE | EDGE User’s Guide | Remote Commanding Capability »

Introduction

We have added a tcl package which allows you to browse, resolve, and publish services on the network using DNS Service Discovery (DNS-SD or DNSSD)

If you are not familiar with DNS-SD, you can read the following:

If you have ever noticed iTunes detect other libraries on the network, or automatically detect a pair of speakers on the network, or detect printers without having to load drivers, you are witnessing DNS-SD at work. Mac's implementation of this on Mac and Windows is known as "Bonjour" and was formerly called "Rendezvous".

Usage

Publishing a Service

To use DNS-SD for publishing/registering a service, be aware that this is already being handled in the "register_local_service" wrapper procedure in "gui/dnssd.tcl". To register a service, simply include this tcl file in your script:

# If dnssd.tcl was not sourced before us, source it now
if { ![info exists dnssd_tcl_loaded] } {
    source $env(GUI_HOME)/dnssd.tcl
}

Browsing and Resolving Services

For browsing and resolving services, you will want to use the bonjour package directly. To use the package in your tcl scripts, you must first include the bonjour package, for example:

# Turn off any warnings from avahi
global env
set env(AVAHI_COMPAT_NOWARN) 1

package require Tcl 8.5
package require bonjour

One you have included the package in your script, you can use the following commands and parameters to publish, browse and resolve DNSSD services on your network:

  • ::bonjour::browse start <regtype> <callback> - This procedue begins a browse operation for a given service type. Every time a service is added or removed to the list of running services, callback will be executed.
    • regtype - The service type to browse (i.e., _http._tcp)
    • callback - The command to call when a service is added or removed from the list of running services. Three arguments will be appended to the command:
      • the action (either add or remove)
      • the service name
      • the domain
  • ::bonjour::browse stop <regtype> - This procedure stops a browse operation. The callback registered for regtype will no longer be called and no new services will be aded.
    • regtype - The service type (i.e., _http._tcp)
  • ::bonjour::resolve <name> <regtype> <domain> <script> - This procedure resolves the given service name into a hostname and port.
    • name - The name of the service to resolve
    • regtype - The service type (i.e., _http._tcp)
    • domain - The domain for the service, as returned by the browse callback.
    • script - The script to execute when the resolution has completed. Four arguments will be appended to the callback script:
      • The full service name
      • The hostname
      • The port
      • a list of txt records for the service. The list of records will be of the form {key value ?key value? ...}.
  • @::bonjour::resolve_address <script>@ - This procedure resolves the address of the given host name.
    • @hostname@ - the host name
    • @script@ - The script to execute when the resolution has completed. The IP address will be appended to the callback script.
  • ::bonjour::register ?options? <regtype> <port> ?txt-record? - This procedure registers a new service using Bonjour.
    • options - Either -name, followed by the desired service name, or -- (double dash) to explicitly indicate the end of options.
    • regtype - The service type (i.e., _http._tcp)
    • port - The port number for the service
    • txt-record - This argument is optional and specifies a list of txt record entries. The list should be of the form {key value ?key value? ...}.
  • ::bonjour::register_with_name <service_name> <regtype> <port> ?txt-record? - This procedure registers a new service using Bonjour but using the service_name provided rather than letting Bonjour choose one.
    • service_name - The service name (i.e., "My service on [info hostname])
    • regtype - The service type (i.e., _http._tcp)
    • port - The port number for the service
    • txt-record - This argument is optional and specifies a list of txt record entries. The list should be of the form {key value ?key value? ...}.

« Import Lightwave models into EDGE | EDGE User’s Guide | Remote Commanding Capability »

⚠️ **GitHub.com Fallback** ⚠️