nameserv(n)
π nameserv β Name service facility, Client π
okay so bestie, this is the client half of Tcllib's name service facility β the nameserv(n) page, part 1 of 2, so don't go anywhere. β¨
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require nameserv ?0.4.3?
package require comm
package require logger
::nameserv::bind name data
::nameserv::release
::nameserv::search ?-async|-continuous? ?pattern?
::nameserv::protocol
::nameserv::server_protocol
::nameserv::server_features
::nameserv::cget -option
::nameserv::configure
::nameserv::configure -option
::nameserv::configure -option value...
$result destroy
$result filled
$result get name
$result names
$result size
$result getall ?pattern?
πΈ DESCRIPTION πΈ
Bestie, real talk: read Name service facility, introduction first. Like, actually. It's the prerequisite. No skipping, I'm watching. π
This package hands you a client for the name service facility β and that facility is implemented over in the package nameserv::server.
And important: this service is built on top of, and for, the package comm. It has literally nothing to do with the Internet's Domain Name System. Zero. None. If that's what you came for, go look at Tcllib's packages dns and resolv instead, bestie. Different vibe entirely. π
π API π
The package exports eight commands, and here they all are, one by one:
::nameserv::bind name dataβ Whoever calls this registersnameas their name in the configured name service, and also tacks a piece ofdataonto it. The service does nothing with that info beyond storing it and handing it back as part of search results. What it means is entirely up to whatever apps are using the name service. A generally useful choice would be an identifier for a communication endpoint managed by the packagecommβ then anybody who retrieves the name can immediately talk to that endpoint, i.e. the registering application. Iconic, honestly.
Also important: a caller can register itself under more than one name, and each name gets its own piece of data. π«Ά
Heads up: the name service β and therefore this command β will throw an error if the name you picked is already registered. Pick a better name, girl. π
::nameserv::releaseβ Invoking this releases all names (and their data) registered by all previous::nameserv::bindcalls from this client. And note: the name service runs this command implicitly when it loses the connection to this client. So ghosting the server = auto-release. π::nameserv::search ?-async|-continuous? ?pattern?β Searches the name service for every registered name matching the given glob-pattern. Don't specify one? It defaults to*, which matches everything. The result is a dictionary mapping the matching names to the data associated with them at bind-time.
But if you specified either -async or -continuous, the result changes β now it's the Tcl command of an object holding the actual result. These two options are supported if and only if the service you're connected to supports the protocol feature Search/Continuous. (Conditional queen. π)
- For
-async, the result object gets asynchronously filled with the entries matching the pattern at the time of the search, and then it's frozen β never modified again. -continuousextends that by also continuously monitoring the service for additions and removals of entries matching the pattern, and updating the object's contents accordingly. Main character behaviour, fr fr.
Not me reminding you: the caller is responsible for configuring the object with a callback so you actually get notified when the current result (or further changes) arrive. Do it. Don't just stare at it. π
For more on this object, see section ASYNCHRONOUS AND CONTINUOUS SEARCHES.
::nameserv::protocolβ Returns the highest version of the name service protocol supported by the package.::nameserv::server_protocolβ Returns the highest version of the name service protocol supported by the name service the client is currently connected to.::nameserv::server_featuresβ Returns a list containing the names of the features of the name service protocol which are supported by the name service the client is currently connected to. Vibe check on your server. π::nameserv::cget -optionβ Returns the currently configured value for the specified-option. Supported options + what they mean = section OPTIONS.::nameserv::configureβ In this form, returns a dictionary of all supported options and their current values. Again, section OPTIONS.::nameserv::configure -optionβ In this form, it's an alias for::nameserv::cget -option. Section OPTIONS. You see the pattern. π::nameserv::configure -option value...β In this form, you configure one or more of the supported options. At least one option has to be specified, and each option is followed by its new value. (Yes. Section OPTIONS.)
Big caveat, bestie: this form works only as long as the client hasn't contacted the name service yet. Once contact is made, reconfiguration is not possible anymore. So this form is for initializing the client before it's used. The commands that force a contact with the name service are:
bindreleasesearchserver_protocolserver_features
π¦ CONNECTION HANDLING π¦
The client automatically connects to the service the first time one of the commands below runs β or whenever one of them runs after the connection was lost, when it was lost. Self-healing era. β¨
bindreleasesearchserver_protocolserver_features
Since version 0.2 of the client, it generates an event when the connection is lost, so higher layers can do extra stuff. This happens via the support package uevent. This package β and all other name-service-related packages β hereby reserve the uevent-tag nameserv. All their events get posted to that tag. π·οΈ
π EVENTS π
This package generates exactly one event: lost-connection. The detail information handed to that event is a Tcl dictionary. The only key in that dictionary is reason, and its value is a string describing why the connection was lost. That string is supplied by the underlying communication package, i.e. comm. So it's not us being vague β blame comm. π
β OPTIONS β
The options the client supports are all about which name service to contact, i.e. where that name service lives. Here they are:
-host name|ipaddressβ Specifies the host the name service you want to contact is running on, either bynameor byipaddress. The initial default islocalhost, i.e. it expects to contact a name service running on the same host as the application using this package. Home sweet home. π-port numberβ Specifies the port the name service you want to contact is listening on. It has to be a positive integer number (> 0) not greater than65536(unsigned short). The initial default is the number returned by the command::nameserv::common::port, as provided by the package::nameserv::common. Default so cute you don't even have to think about it.
πΈ ASYNCHRONOUS AND CONTINUOUS SEARCHES πΈ
Asynchronous and continuous searches get invoked by passing either -async or -continuous as an argument to ::nameserv::search. Simple as that.
Note that these two options are supported if and only if the service the client is connected to supports the protocol featureSearch/Continuous. The service provided by the package::nameserv::serverdoes this since version 0.3. So like, check your server's version before you get your hopes up. π
For these searches, the result of the search command is the Tcl command of an object holding the actual result. The API these objects provide is:
π Options π
-command command_prefixβ This option has to be set if a user of the result object wants asynchronous notifications when the search result arrives, or when changes to it arrive.
And like β sure, you could poll for the initial search result via the method filled, and poll for subsequent changes by comparing the output of getall against a saved copy. But that is not the recommended behaviour, bestie. Setting the -command callback and processing notifications as they arrive is much more efficient. Trust.
command_prefix is called with two arguments: the type of change, and the data of the change. The type is either add or remove, indicating new data or deleted data, respectively. The data of the change is always a dictionary listing the added/removed names and their associated data.
The first change reported for a search is always the set of matching entries at the time of the search. First notification = the whole opening roster. πβ¨
π¦ Methods π¦
$result destroyβ Destroys the object and cancels any continuous monitoring of the service the object may have had active. Bye bitch, respectfully. π$result filledβ The result is a boolean value indicating whether the search result has already arrived (True), or not (False).$result get nameβ Returns the data associated with the givennameat bind-time.$result namesβ Returns a list containing all names known to the object at the time of the invocation.$result sizeβ Returns an integer value specifying the size of the result at the time of the invocation.$result getall ?pattern?β Returns a dictionary containing the search result at the time of the invocation, mapping the matching names to the data associated with them at bind-time.
π HISTORY π
- 0.3.1 β Fixed SF Bug 1954771. π
- 0.3 β Extended the client with the ability to perform asynchronous and continuous searches.
- 0.2 β Extended the client with the ability to generate events when it loses its connection to the name service. Based on package
uevent. - 0.1 β Initial implementation of the client. The origin story. π±
part 1 done, bestie β more parts are coming, don't close the tab π
π BUGS, IDEAS, FEEDBACK π
Okay bestie, real talk. This doc? And the whole package it's describing? It's gonna have bugs. And other problems. Like, undoubtedly. That's just the vibe of software, no cap. π
So if you find something cursed, please report it in the category nameserv of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. π«Ά
And listen β if you have ideas for enhancements, for the package or for the documentation, those go there too. We want them. Both of them. All of them. π
π§ Proposing code changes π§
When you're proposing code changes, you need to provide unified diffs, i.e. the output of:
diff -u
That's the format. That's the one. Don't be mysterious about it. β¨
β οΈ Also, heads up: attachments are strongly preferred over inlined patches. Like, strongly. Fr fr.
So how do you attach? Easy:
- Create the ticket.
- Immediately after it's created, go to the Edit form of that ticket.
- Use the left-most button in the secondary navigation bar. That's the one. That's the door. πͺβ¨
π SEE ALSO π
nameserv::common(n)nameserv::server(n)
π KEYWORDS π
- client
- name service
π CATEGORY π
Networking
Β©οΈ COPYRIGHT Β©οΈ
Copyright (c) 2007-2008 Andreas Kupries <andreas_kupries@users.sourceforge.net>
okay that's the whole page bestie, we did it, we made it to the end π
This one shipped out of tcllib, version 0.4.3, and it's the nameserv(n) page β so if you ever need to double-check which build you're reading, that's the little footprint it left at the bottom. No date on this one, just the version and the name. Slay. π
β¨ Go report a bug. Or fix one. Main character energy either way. π
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- Copyright (c) 2007-2008 Andreas Kupries <andreas_kupries@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms