comm(n)
π comm(n) β remote communication, but make it a group chat π
okay bestie, welcome to the comm(n) page β Remote communication. It's a remote communication facility for Tcl (8.5 and later) and honestly? she's iconic. let's get into it π
β¨ NAME β¨
comm β A remote communication facility for Tcl (8.5 and later)
π¦ SYNOPSIS π¦
package require Tcl 8.5 9
package require comm ?4.7.3?
::comm::comm send ?-async? ?-command callback? id cmd ?arg arg ...?
::comm::comm self
::comm::comm interps
::comm::comm connect ?id?
::comm::comm new chan ?name value ...?
::comm::comm channels
::comm::comm config
::comm::comm config name
::comm::comm config ?name value ...?
::comm::comm shutdown id
::comm::comm abort
::comm::comm destroy
::comm::comm hook event ?+? ?script?
::comm::comm remoteid
::comm::comm_send
::comm::comm return_async
$future return ?-code code? ?value?
$future configure ?-command ?cmdprefix??
$future cget -command
πΈ DESCRIPTION πΈ
So. The comm command gives you an inter-interpreter remote execution facility β and it's basically Tk's send(n) but with a glow-up. The vibe is the same, but instead of routing through the X server for the communication path, it uses sockets. Which means:
- it works with multiple interpreters π«Ά
- it works on Windows and Macintosh systems π»
- and it gives you actual control over the remote execution path π
These commands work just like send and winfo interps:
::comm::comm send ?-async? id cmd ?arg arg ...?
::comm::comm interps
And ngl? That's all you really need to know to use comm. That's the whole vibe check. β¨
π COMMANDS π
The package initializes ::comm::comm as the default chan. periodt.
comm names communication endpoints with an id unique to each machine. Before you send commands, you need the id of another interpreter. And here's the thing β unlike Tk's send, comm doesn't implicitly know the id's of all the interpreters on the system. She's not psychic, bestie. π The following four methods make up the basic comm interface.
::comm::comm send ?-async? ?-command callback? id cmd ?arg arg ...?β this invokes the given command in the interpreter named byid. The command waits for the result, and remote errors are returned β unless you gave-asyncor-command. If-asyncis given,sendreturns immediately and there is no further notification of result. If-commandis used,callbackspecifies a command to invoke when the result is received. These two options are mutually exclusive, so pick one, not both. π«
The callback will receive arguments in the form -option value, suitable for array set. The options are:
-idβ the comm id of the interpreter that received the command-serialβ a unique serial for each command sent to a particular comm interpreter-chanβ the comm channel name-codeβ the result code of the command-errorcodeβ the errorcode, if any, of the command-errorinfoβ the errorinfo, if any, of the command-resultβ the return value of the command
If connection is lost before a reply is received, the callback will be invoked with a connection lost message with -code equal to -1. π And when -command is used, the command returns the unique serial for the command.
::comm::comm selfβ returns the id for this channel. that's it, that's the whole thing. main character energy β¨::comm::comm interpsβ returns a list of all the remote id's to which this channel is connected.commlearns a new remote id when a command is first issued it, or when a remote id first issues a command to this comm channel. Also,::comm::comm idsis an alias for this method, so use whichever one feels right π«Ά::comm::comm connect ?id?β whereas::comm::comm sendwill automatically connect to the given id, this one forces a connection to a remote id without sending a command. After this, the remote id will appear in::comm::comm interps. no cap. π₯
π EVAL SEMANTICS π
The evaluation semantics of ::comm::comm send are intended to match Tk's send exactly. Which means comm evaluates arguments on the remote side.
If you find that ::comm::comm send doesn't work for a particular command, try the same thing with Tk's send and see if the result is different. If there is a problem, please report it. Like, for instance β there was had one report that this command produced an error. And note that the equivalent send command also produces the same error. so like, it's not a comm thing, it's an everyone thing π
% ::comm::comm send id llength {a b c}
wrong # args: should be "llength list"
% send name llength {a b c}
wrong # args: should be "llength list"
The eval hook (described below) can be used to change from send's double eval semantics to single eval semantics. iykyk.
π¦ MULTIPLE CHANNELS π¦
More than one comm channel (or listener) can be created in each Tcl interpreter. This allows flexibility to create full and restricted channels. For instance, hook scripts are specific to the channel they are defined against. like, she's loyal to her channel π
::comm::comm new chan ?name value ...?β this creates a new channel and Tcl command with the given channel name. This new command controls the new channel and takes all the same arguments as::comm::comm. Any remaining arguments are passed to theconfigmethod. The fully qualified channel name is returned. slay.::comm::comm channelsβ this lists all the channels allocated in this Tcl interpreter. the whole roster π
The default configuration parameters for a new channel are:
"-port 0 -local 1 -listen 0 -silent 0"
The default channel ::comm::comm is created with:
"::comm::comm new ::comm::comm -port 0 -local 1 -listen 1 -silent 0"
π CHANNEL CONFIGURATION π
The config method acts similar to fconfigure, in that it sets or queries configuration variables associated with a channel.
::comm::comm config
::comm::comm config name
::comm::comm config ?name value ...?
- When given no arguments,
configreturns a list of all variables and their value. - With one argument,
configreturns the value of just that argument. - With an even number of arguments, the given variables are set to the given values.
These configuration variables can be changed (descriptions of them are elsewhere in this manual page):
-listen?0|1?-local?0|1?-port?port?-silent?0|1?-socketcmd?commandname?-interp?interpreter?-events?eventlist?
These configuration variables are read only:
-chanchan-serialn-socketsockIn
When config changes the parameters of an existing channel (with the exception of -interp and -events), it closes and reopens the listening socket. An automatically assigned channel id will change when this happens. Recycling the socket is done by invoking ::comm::comm abort, which causes all active sends to terminate. heads up bestie, that's a real thing that happens π³
π ID/PORT ASSIGNMENTS π
comm uses a TCP port for endpoint id. The interps (or ids) method merely lists all the TCP ports to which the channel is connected. By default, each channel's id is randomly assigned by the operating system (but usually starts at a low value around 1024 and increases each time a new socket is opened). This behavior is accomplished by giving the -port config option a value of 0.
Alternately, a specific TCP port number may be provided for a given channel. As a special case, comm contains code to allocate a a high-numbered TCP port (>10000) by using -port {}. Note that a channel won't be created and initialized unless the specific port can be allocated. so like, no port, no channel, no vibes π
As a special case, if the channel is configured with -listen 0, then it will not create a listening socket and will use an id of 0 for itself. Such a channel is only good for outgoing connections (although once a connection is established, it can carry send traffic in both directions π«Ά). As another special case, if the channel is configured with -silent 0, then the listening side will ignore connection attempts where the protocol negotiation phase failed, instead of throwing an error. β¨
π EXECUTION ENVIRONMENT π
A communication channel in its default configuration will use the current interpreter for the execution of all received scripts, and of the event scripts associated with the various hooks.
β οΈ This is an insecure setup, and it can be changed by the user via the two options-interp, and-events. bestie. please pay attention to this part. π
When -interp is set, all received scripts are executed in the slave interpreter specified as the value of the option. This interpreter is expected to exist before configuration β i.e. it is the responsibility of the user to create it. However, afterward the communication channel takes ownership of this interpreter, and will destroy it when the communication channel is destroyed. π
Note that reconfiguration of the communication channel to either a different interpreter or the empty string will release the ownership without destroying the previously configured interpreter. The empty string has a special meaning: it restores the default behaviour of executing received scripts in the current interpreter.
Also of note is that replies and callbacks (a special form of reply) are not considered as received scripts. They are trusted, part of the internal machinery of comm, and therefore always executed in the current interpreter. they're on the VIP list, essentially π
Even if an interpreter has been configured as the execution environment for received scripts, the event scripts associated with the various hooks will by default still be executed in the current interpreter. To change this, use the option -events to declare a list of the events whose scripts should be executed in the declared interpreter as well. The contents of this option are ignored if the communication channel is configured to execute received scripts in the current interpreter. π¦
πΈ REMOTE INTERPRETERS πΈ
By default, each channel is restricted to accepting connections from the local system. This can be overridden by using the -local 0 configuration option. For such channels, the id parameter takes the form { id host }.
π¨ WARNING: The host must always be specified in the same form (e.g., as either a fully qualified domain name, plain hostname or an IP address). do not mix and match, bestie, she will not forgive you π
β¨ CLOSING CONNECTIONS β¨
These methods give control over closing connections:
::comm::comm shutdown idβ this closes the connection toid, aborting all outstanding commands in progress. Note that nothing prevents the connection from being immediately reopened by another incoming or outgoing command. she's got no chill like that π::comm::comm abortβ this invokesshutdownon all open connections in this comm channel. the nuclear option, but make it cute π₯
okay so bestie, let's talk about ::comm::comm destroy. This icon aborts ALL connections and then yeets the comm channel itself, including closing the listening socket. π
But wait β there's special code that lets you close the default ::comm::comm channel without destroying the ::comm::comm command itself. Doing that closes the listening socket, so no incoming or outgoing commands on the channel. It's giving "shutdown but keep the command". And this sequence right here reinitializes the default channel:
"::comm::comm destroy; ::comm::comm new ::comm::comm"
Also, when a remote connection dips out (like the remote exited or called shutdown), comm can trigger an application callback. You can use this to clean up or restart some side process, no cap. Check out the lost callback below. π¦
β¨ CALLBACKS β¨
This is the mechanism for setting hooks for particular events. It's giving "customize your comm experience". π
::comm::comm hook event ?+? ?script?
This uses a syntax similar to Tk's bind command. Prefixing script with a + causes the new script to be appended. Without this, a new script replaces any existing script. When invoked without a script, no change is made. In all cases, the new hook script is returned by the command. So it's like "set it and forget it" but also "get it back". π₯
When an event occurs, the script associated with it is evaluated with the listed variables in scope and available. The return code (not the return value) of the script is commonly used to decide how to further process after the hook.
Common variables include:
chanβ the name of the comm channel (and command)idβ the id of the remote in questionfidβ the file id for the socket of the connection
These are the defined events:
connecting
Variables: chan, id
This hook is invoked before making a connection to the remote named in id. An error return (via error) will abort the connection attempt with the error. Example:
% ::comm::comm hook connecting {
if {[string match {*[02468]} $id]} {
error "Can't connect to even ids"
}
}
% ::comm::comm send 10000 puts ok
Connect to remote failed: Can't connect to even ids
%
So like, you can gatekeep connections. πͺ
connected
Variables: chan, fid, id, host, and port.
This hook is invoked immediately after making a remote connection to id, allowing arbitrary authentication over the socket named by fid. An error return (via error) will close the connection with the error. host and port are merely extracted from the id; changing any of these will have no effect on the connection, however. It is also possible to substitute and replace fid. So like, you can do auth stuff. π
incoming
Variables: chan, fid, addr, and remport.
Hook invoked when receiving an incoming connection, allowing arbitrary authentication over socket named by fid. An error return (via error) will close the connection with the error. Note that the peer is named by remport and addr but that the remote id is still unknown. Example:
::comm::comm hook incoming {
if {[string match 127.0.0.1 $addr]} {
error "I don't talk to myself"
}
}
eval
Variables: chan, id, cmd, and buffer.
This hook is invoked after collecting a complete script from a remote but before evaluating it. This allows complete control over the processing of incoming commands. cmd contains either send or async. buffer holds the script to evaluate. At the time the hook is called, $chan remoteid is identical in value to id.
By changing buffer, the hook can change the script to be evaluated. The hook can short circuit evaluation and cause a value to be immediately returned by using return result (or, from within a procedure, return -code return result). An error return (via error) will return an error result, as is if the script caused the error. Any other return will evaluate the script in buffer as normal. For compatibility with 3.2, break and return -code break result is supported, acting similarly to return {} and return -code return result.
Examples, bestie! These are so iconic:
[1] augmenting a command
% ::comm::comm send [::comm::comm self] pid
5013
% ::comm::comm hook eval {puts "going to execute $buffer"}
% ::comm::comm send [::comm::comm self] pid
going to execute pid
5013
[2] short circuiting a command
% ::comm::comm hook eval {puts "would have executed $buffer"; return 0}
% ::comm::comm send [::comm::comm self] pid
would have executed pid
0
[3] Replacing double eval semantics
% ::comm::comm send [::comm::comm self] llength {a b c}
wrong # args: should be "llength list"
% ::comm::comm hook eval {return [uplevel #0 $buffer]}
return [uplevel #0 $buffer]
% ::comm::comm send [::comm::comm self] llength {a b c}
3
[4] Using a slave interpreter
% interp create foo
% ::comm::comm hook eval {return [foo eval $buffer]}
% ::comm::comm send [::comm::comm self] set myvar 123
123
% set myvar
can't read "myvar": no such variable
% foo eval set myvar
123
[5] Using a slave interpreter (double eval)
% ::comm::comm hook eval {return [eval foo eval $buffer]}
[6] Subverting the script to execute
% ::comm::comm hook eval {
switch -- $buffer {
a {return A-OK}
b {return B-OK}
default {error "$buffer is a no-no"}
}
}
% ::comm::comm send [::comm::comm self] pid
pid is a no-no
% ::comm::comm send [::comm::comm self] a
A-OK
reply
Variables: chan, id, buffer, ret, and return().
This hook is invoked after collecting a complete reply script from a remote but before evaluating it. This allows complete control over the processing of replies to sent commands. The reply buffer is in one of the following forms:
return resultreturn -code code resultreturn -code code -errorinfo info -errorcode ecode msg
For safety reasons, this is decomposed. The return result is in ret, and the return switches are in the return array:
return(-code)return(-errorinfo)return(-errorcode)
Any of these may be the empty string. Modifying these four variables can change the return value, whereas modifying buffer has no effect.
callback
Variables: chan, id, buffer, ret, and return().
Similar to reply, but used for callbacks.
lost
Variables: chan, id, and reason.
This hook is invoked when the connection to id is lost. Return value (or thrown error) is ignored. reason is an explanatory string indicating why the connection was lost. Example:
::comm::comm hook lost {
global myvar
if {$myvar(id) == $id} {
myfunc
return
}
}
π« UNSUPPORTED π«
These interfaces may change or go away in subsequence releases. So like, use at your own risk. π
::comm::comm remoteid
Returns the id of the sender of the last remote command executed on this channel. If used by a proc being invoked remotely, it must be called before any events are processed. Otherwise, another command may get invoked and change the value.
::comm::comm_send
Invoking this procedure will substitute the Tk send and winfo interps commands with these equivalents that use ::comm::comm.
proc send {args} {
eval ::comm::comm send $args
}
rename winfo tk_winfo
proc winfo {cmd args} {
if {![string match in* $cmd]} {
return [eval [list tk_winfo $cmd] $args]
}
return [::comm::comm interps]
}
π SECURITY π
Starting with version 4.6 of the package an option -socketcmd is supported, allowing the user of a comm channel to specify which command to use when opening a socket. Anything which is API-compatible with the builtin ::socket (the default) can be used.
The envisioned main use is the specification of the tls::socket command, see package tls, to secure the communication.
# Load and initialize tls
package require tls
tls::init -cafile /path/to/ca/cert -keyfile ...
# Create secured comm channel
::comm::comm new SECURE -socketcmd tls::socket -listen 1
...
The sections Execution Environment and Callbacks are also relevant to the security of the system, providing means to restrict the execution to a specific environment, perform additional authentication, and the like.
β³ BLOCKING SEMANTICS β³
There is one outstanding difference between comm and send. When blocking in a synchronous remote command, send uses an internal C hook (Tk_RestrictEvents) to the event loop to look ahead for send-related events and only process those without processing any other events. In contrast, comm uses the vwait command as a semaphore to indicate the return message has arrived. The difference is that a synchronous send will block the application and prevent all events (including window related ones) from being processed, while a synchronous ::comm::comm send will block the application but still allow other events to get processed. In particular, after idle handlers will fire immediately when comm blocks.
okay bestie, so what do we even do about all this? π first things first β clock that this behavior will come from any code using vwait to block and wait for an event to occur. so it's not even a comm-exclusive problem, it's a whole vibe.
here's the tea on the possible fixes:
- we could change comm to do blocking I/O on the socket, which would give us send-like blocking semantics β but the price tag is multiple channel support, and that feature is genuinely too iconic to lose, so that one's a no π ββοΈ
- the remaining approaches all involve a new loadable module written in C, which is, lowkey, somewhat against the philosophy of comm π
- one way: create a modified version of the
vwaitcommand that allows the event flags passed toTcl_DoOneEventto be specified. for comm, just theTCL_FILE_EVENTSwould be processed β¨ - another way: implement a mechanism like
Tk_RestrictEvents, but apply it to the Tcl event loop instead (since comm doesn't require Tk) π¦
- one way: create a modified version of the
- one of these approaches will be available in a future comm release as an optional component π
β¨ ASYNCHRONOUS RESULT GENERATION β¨
so by default, the result returned by a remotely invoked command is just the result sent back to the invoker. which means the result is generated synchronously, and the server handling the call is blocked for the whole duration of the command π
that's tolerable as long as you're only invoking short-running commands on the server. but long-running commands β think database queries β make this a whole problem. one command can prevent the processing of requests from all the other clients for an arbitrary period of time. not the vibe π«
before version 4.5 of comm, the only solution was to rewrite the server command to use the Tcl builtin command vwait, or one of its relatives like tkwait, to open a new event loop which processes requests while the long-running operation is executed. but bestie, that has its own perils: it makes it possible to both overflow the Tcl stack with a large number of event loops, and to have newer requests block the return of older ones, since the event loops have to be unwound in the order of their creation π
the proper solution is to have the invoked command indicate to comm that it cannot β or will not β deliver an immediate, synchronous result, but will do so later. at that point the framework can put sending the actual result on hold and continue processing requests using the main event loop. no blocking, no nesting of event loops, periodt π«Ά at some future date the long-running operation delivers the result to comm, via the future object, which is then forwarded to the invoker as usual.
the necessary support for this solution has been added to comm since version 4.5, in the form of the new method return_async π
::comm::comm return_async
this command is used by a remotely invoked script to notify the comm channel which invoked it that the result to send back to the invoker is not generated synchronously. if this command is not called, the default/standard behaviour of comm is to send the synchronously generated result of the script itself to the invoker.
the result of return_async is an object. this object, called a future, is where the result of the script has to be delivered to when it becomes ready. when that happens it will take all the necessary actions to deliver the result to the invoker of the script, and then destroy itself πΈ should comm have lost the connection to the invoker while the result is being computed, the future will not try to deliver the result it got, but just destroy itself. the future can be configured with a command to call when the invoker is lost. this enables the user to implement an early abort of the long-running operation, should this be supported by it.
an example, because seeing it in action is everything:
# Procedure invoked by remote clients to run database operations.
proc select {sql} {
# Signal the async generation of the result
set future [::comm::comm return_async]
# Generate an async db operation and tell it where to deliver the result.
set query [db query -command [list $future return] $sql]
# Tell the database system which query to cancel if the connection
# goes away while it is running.
$future configure -command [list db cancel $query]
# Note: The above will work without problem only if the async
# query will nover run its completion callback immediately, but
# only from the eventloop. Because otherwise the future we wish to
# configure may already be gone. If that is possible use 'catch'
# to prevent the error from propagating.
return
}
the API of a future object is:
$future return ?-code code? ?value?β use this method to tell the future that the long-running operation has completed. the arguments are an optional return value (which defaults to the empty string) and the Tcl return code (which defaults toOK). the future will deliver this information to the invoker β if the connection was not lost in the meantime β and then destroy itself. if the connection was lost, it will do nothing but destroy itself π$future configure ?-command ?cmdprefix??and$future cget -commandβ these methods let the user retrieve and set a command to be called if the connection the future belongs to has been lost π
π COMPATIBILITY π
comm exports itself as a package π¦ the package version number is in the form major.minor, where the major version will only change when a non-compatible change happens to the API or protocol. minor bug fixes and changes will only affect the minor version. to load comm, this command is usually used:
package require comm 3
note that requiring no version (or a specific version) can also be done π
the revision history of comm includes these releases:
4.6.3β Fixed ticket[ced0d60fc9]. Added proper detection of eof on a socket, properly closing it π₯4.6.2β Fixed bugs2972571and3066872, the first a misdetection of quoted brace after double backslash, the other a blockinggetsmaking for an obvious (hinsight) DoS attack on comm channels π4.6.1β Changed the implementation ofcomm::commCollectto emulatelindex's pre-Tcl 8 behaviour, i.e. it was given the ability to parse out the first word of a list, even if the whole buffer is not a well-formed list. Without this change the first word could only be extracted if the whole buffer was a well-formed list (ever since Tcl 8), and in a ver-high-load situation, i.e. a server sending lots and/or large commands very fast, this may never happen, eventually crashing the receiver when it runs out of memory. With the change the receiver is always able to process the first word when it becomes well-formed, regardless of the structure of the remainder of the buffer π«Ά4.6β Added the option-socketcmdenabling users to override how a socket is opened. The envisioned main use is the specification of thetls::socketcommand, see packagetls, to secure the communication β¨4.5.7β Changed handling of ports already in use to provide a proper error message π’4.5.6β Bugfix in the replacement forvwait, made robust against of variable names containing spaces4.5.5β Bugfix in the handling of hooks, typo in variable name π4.5.4β Bugfix in the handling of the result received by thesendmethod. Replaced anafter idle unset resultwith an immediate unset, with the information saved to a local variable. Theafter idlecan spill into a forked child process if there is no event loop between its setup and the fork. This may bork the child if the next event loop is thevwaitof comm'ssenda few lines above theafter idle, and the child used the same serial number for its next request. In that case the parent'safter idle unsetwill delete the very array element the child is waiting for, unlocking thevwait, causing it to access a now missing array element, instead of the expected result π4.5.3β Bugfixes in the wrappers for the builtinupdateandvwaitcommands4.5.2β Bugfix in the wrapper for the builtinupdatecommand4.5.1β Bugfixes in the handling of-interpfor regular scripts. The handling of the buffer was wrong for scripts which are a single statement as list. Fixed missing argument to new commandcommSendReply, introduced by version 4.5. Affected debugging π4.5β New server-side feature. The command invoked on the server can now switch comm from the standard synchronous return of its result to an asynchronous (defered) return. Due to the use ofsnitto implement the future objects used by this feature, from this version on comm requires at least Tcl 8.3 to run. Please read the section Asynchronous Result Generation for more details π4.4.1β Bugfix in the execution of hooks4.4β Bugfixes in the handling of-interpfor regular and hook scripts. Bugfixes in channel cleanup π§Ή4.3.1β Introduced-interpand-eventsto enable easy use of a slave interp for execution of received scripts, and of event scripts4.3β Bugfixes, and introduces-silentto allow the user to force the server/listening side to silently ignore connection attempts where the protocol negotiation failed π€«4.2β Bugfixes, and most important, switched toutf-8as default encoding for full i18n without any problems π4.1β Rewrite of internal code to remove old pseudo-object model. Addition ofsend -commandasynchronous callback option4.0β Per request by John LoVerso. Improved handling of error for async invoked commands π«‘3.7β Moved into tcllib and placed in a proper namespace π¦3.6β A bug in the looking up of the remoteid for a executed command could be triggered when the connection was closed while several asynchronous sends were queued to be executed3.5β Internal change to how reply messages from asendare handled. Reply messages are now decoded into the value to pass toreturn; a newreturnstatement is then cons'd up to with this value. Previously, the return code was passed in from the remote as a command to evaluate. Since the wire protocol has not changed, this is still the case. Instead, the reply handling code decodes the reply message π- 3.4 β bestie dropped so much source commentary β¨ and finally documented the config variables in this man page. Also fixed a bug where losing the connection would give you an error about a variable named
pendinginstead of, you know, the actual message about the lost connection π. Andcomm idsis now an alias forcomm interps(it used to be an alias forcomm chansβ glow-up era). Since the method invocation change back in 3.0,breakand other exceptional conditions were NOT being returned correctly fromcomm send, which is giving bug fr. Fixed by removing that extra level of indirection into the internal procedurecommSendπ«Ά. Also added propagation of theerrorCodevariable. The result: these commands return exactly as they would withsend:
comm send id break
catch {comm send id break}
comm send id expr 1 / 0
Added a brand new hook for reply messages π₯. Reworked method invocation to avoid the use of comm:* procedures, which also cut the invocation time down by 40% (ate, no crumbs). Documented comm config β because this manual page was still listing the defunct comm init π.
- 3.3 β some minor bugs were corrected and the documentation got a little cleanup π§. Added some examples for hooks. The return semantics of the
evalhook were changed (iykyk). - 3.2 β a new wire protocol, version 3, was added β¨. It's backwards compatible with version 2 but adds an exchange of supported protocol versions so we can do protocol negotiation in the future, main character energy. Several bugs with the hook implementation were fixed. A new section of the man page on blocking semantics was added.
- 3.1 β all the documented hooks were implemented π
.
commLostHookwas removed. A bug incomm newwas fixed. - 3.0 β this is a new version of
commwith several major changes π. There's a new way of creating the methods available under thecommcommand. Thecomm initmethod has been retired and is replaced bycomm configure, which allows access to many of the well-defined internal variables. This also generalizes the options available tocomm new. Finally, there is now a protocol version exchanged when a connection is established. This will allow for future on-wire protocol changes. Currently, the protocol version is set to2. - 2.3 β
comm idswas renamed tocomm channels. General support forcomm hookwas fully implemented, but only the lost hook exists, and it was changed to follow the general hook API.commLostHookwas unsupported (replaced bycomm hook lost) andcommLostwas removed. - 2.2 β the
diedhook was renamedlost, to be accessed bycommLostHookand an early implementation ofcomm losthook. As such,commDiedis nowcommLost. - 2.1 β unsupported method
comm remoteidwas added π. - 2.0 β
commhas been rewritten from scratch (but is fully compatible with Comm 1.0, without the requirement to use obTcl) π.
π TLS SECURITY CONSIDERATIONS π
This package uses the TLS package to handle the security for https urls and other socket connections π.
But listen β policy decisions like the set of protocols to support and what ciphers to use are not the responsibility of TLS, nor of this package itself. Such decisions are the responsibility of whichever application is using the package, and are likely influenced by the set of servers the application will talk to as well π«Ά.
For example, in light of the recent POODLE attack [http://googleonlinesecurity.blogspot.co.uk/2014/10/this-poodle-bites-exploiting-ssl-30.html] discovered by Google, many servers will disable support for the SSLv3 protocol. To handle this change the applications using TLS must be patched, and not this package, nor TLS itself. Such a patch may be as simple as generally activating tls1 support, as shown in the example below β¬οΈ.
package require tls
tls::init -tls1 1 ;# forcibly activate support for the TLS1 protocol
... your own application code ...
π AUTHOR π
John LoVerso, John@LoVerso.Southborough.MA.US
http://www.opengroup.org/~loverso/tcl-tk/#comm
π LICENSE π
Please see the file comm.LICENSE that accompanied this source, or http://www.opengroup.org/www/dist_client/caubweb/COPYRIGHT.free.html πΈ.
This license for comm, new as of version 3.2, allows it to be used for free, without any licensing fee or royalty π (yes bestie, free free).
π BUGS π
- If there is a failure initializing a channel created with
::comm::comm new, then the channel should be destroyed. Currently, it is left in an inconsistent state π. - There should be a way to force a channel to quiesce when changing the configuration.
The following items can be implemented with the existing hooks and are listed here as a reminder to provide a sample hook in a future version:
- Allow easier use of a slave interp for actual command execution (especially when operating in
"not local"mode). - Add host list (xhost-like) or
"magic cookie"(xauth-like) authentication to initial handshake.
The following are outstanding todo items:
- Add an interp discovery and name->port mapping. This is likely to be in a separate, optional nameserver. (See also the related work, below.)
- Fix the
{id host}form so as not to be dependent upon canonical hostnames. This requires fixes to Tcl to resolve hostnames!
This man page is bigger than the source file π (iconic, honestly).
π°οΈ ON USING OLD VERSIONS OF TCL π°οΈ
Tcl7.5 under Windows contains a bug that causes the interpreter to hang when EOF is reached on non-blocking sockets π. This can be triggered with a command such as this:
"comm send $other exit"
Always make sure the channel is quiescent before closing/exiting or use at least Tcl7.6 under Windows β.
Tcl7.6 on the Mac contains several bugs. It is recommended you use at least Tcl7.6p2.
Tcl8.0 on UNIX contains a socket bug that can crash Tcl π. It is recommended you use Tcl8.0p1 (or Tcl7.6p2).
π RELATED WORK π
Tcl-DP provides an RPC-based remote execution interface, but is a compiled Tcl extension. See http://www.cs.cornell.edu/Info/Projects/zeno/Projects/Tcl-DP.html.
Michael Doyle <miked@eolas.com> has code that implements the Tcl-DP RPC interface using standard Tcl sockets, much like comm. The DpTcl package is available at http://chiselapp.com/user/gwlester/repository/DpTcl.
Andreas Kupries <andreas_kupries@users.sourceforge.net> uses comm and has built a simple nameserver as part of his Pool library. See http://www.purl.org/net/akupries/soft/pool/index.htm π¦.
π«Ά BUGS, IDEAS, FEEDBACK π«Ά
This document, and the package it describes, will undoubtedly contain bugs and other problems (not me being shady, it's literally in the original π). Please report such in the category comm of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation π.
When proposing code changes, please provide unified diffs, i.e the output of diff -u β¨.
Note further that attachments are strongly preferred over inlined patches π. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.
π SEE ALSO π
π KEYWORDS π
comm, communication, ipc, message, remote communication, remote execution, rpc, secure, send, socket, ssl, tls
π CATEGORY π
Programming tools
β COPYRIGHT β
Copyright (c) 1995-1998 The Open Group. All Rights Reserved.
Copyright (c) 2003-2004 ActiveState Corporation.
Copyright (c) 2006-2009 Andreas Kupries <andreas_kupries@users.sourceforge.net>
And that's a wrap bestie πβ¨ this whole thing lives in tcllib, version 4.7.3, and it's the comm(n) page β go forth and message remotely, you absolute icon π
π«Ά
π¦ 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) 1995-1998 The Open Group\&. All Rights Reserved\&
- Copyright (c) 2003-2004 ActiveState Corporation\&
- Copyright (c) 2006-2009 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