comm_wire(n)
π comm_wire(n) β the comm wire protocol β¨
okay bestie, so this is the comm_wire page from the tcllib docs (manual page, remote communication section, version 3, iykyk) and it's genuinely one of those "only the girlies writing protocol code care" documents. if you're just using comm you can lowkey scroll past. if you're out here building your own compatible implementation or hacking on the package itself, this is your roman empire. periodt. π
π SYNOPSIS
package require comm
π¦ DESCRIPTION
The comm command gives you an inter-interpreter remote execution facility β like Tk's send(n), except it does the whole thing over sockets instead of the X server. the way that it just... works everywhere?? because of that, comm:
- plays nice with multiple interpreters
- runs on Windows and Macintosh systems ππͺ
- gives you control over the remote execution path π
This document right here is a spec of the different versions of the wire protocol that comm uses internally so its endpoints can yap to each other. ngl it has zero relevance to users of comm β it's for developers who wanna:
- modify the package
- write a compatible facility in a different language
- or build some other facility based on the same protocol
π WIRE PROTOCOL VERSION 3 π
β¨ BASIC LAYER
The basic encoding for all data is UTF-8. Because of this, binary data β including the NULL character β can be sent over the wire as is, no armoring needed. we love a layer that just sends it. π
π BASIC MESSAGE LAYER
On top of the Basic Layer we have a message-oriented exchange of data. The totality of all characters written to the channel is a Tcl list, with each element a separate message, each itself a list. The messages in the overall list are separated by EOL.
not me about to warn you:EOLcharacters can occur within the list as well. π You can tell them apart from the message-separatingEOLby the fact that the data from the beginning up to their location is not a valid Tcl list.
EOL is signaled through the linefeed character, i.e LF, or, hex 0x0a. This follows the unix convention for line-endings. slay, consistency. π
As a list, each message is composed of words. Their meaning depends on when the message was sent in the overall exchange. Details in the upcoming sections, bestie π
π«Ά NEGOTIATION MESSAGES β INITIAL HANDSHAKE
The command protocol is defined like this:
- The first message sent by a client to a server, when opening the connection, contains two words. The first word is a list as well, and contains the versions of the wire protocol the client is willing to accept, with the most preferred version first. The second word is the TCP port the client is listening on for connections to itself. The value
0is used here to signal that the client will not listen for connections, i.e. that it is purely for sending commands, and not receiving them. - The first message sent by the server to the client, in response to the message above, contains only one word. This word is a list, containing the string
versas its first element, and the version of the wire protocol the server has selected from the offered versions as the second.
π₯ SCRIPT/COMMAND MESSAGES
All messages coming after the initial handshake consist of three words. These are an instruction, a transaction id, and the payload. The valid instructions are shown below. The transaction ids are used by the client to match any incoming replies to the command messages it sent. Which means a server has to copy the transaction id from a command message to the reply it sends for that message. no pressure or anything β¨
sendasynccommandβ The payload is the Tcl script to execute on the server. It is actually a list containing the script fragments. These fragments are concatenated together by the server to form the full script to execute on the server side. This emulates the Tcl "eval" semantics. In most cases it is best to have only one word in the list, a list containing the exact command.
Examples:
(a) {send 1 {{array get tcl_platform}}}
(b) {send 1 {array get tcl_platform}}
(c) {send 1 {array {get tcl_platform}}}
are all valid representations of the same command. They are generated via
(a') send {array get tcl_platform}
(b') send array get tcl_platform
(c') send array {get tcl_platform}
respectively
replyβ Like the previous three commands, however the tcl script in the payload is highly restricted. It has to be a syntactically valid Tclreturncommand. This contains result code, value, error code, and error info.
Examples:
{reply 1 {return -code 0 {}}}
{reply 1 {return -code 0 {osVersion 2.4.21-99-default byteOrder littleEndian machine i686 platform unix os Linux user andreask wordSize 4}}}
Note that (a), generated by (a'), is the usual form, if only single commands are sent by the client. For example constructed using list, if the command contains variable arguments. Like
send [list array get $the_variable]
These three instructions all invoke the script on the server side. Their difference is in the treatment of result values, and thus determines if a reply is expected. π§
sendβ A reply is expected. The sender is waiting for the result.asyncβ No reply is expected, the sender has no interest in the result and is not waiting for any.commandβ A reply is expected, but the sender is not waiting for it. It has arranged to get a process-internal notification when the result arrives.
π BUGS, IDEAS, FEEDBACK
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category comm of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist](http://core.tcl.tk/tcllib/reportlist). Please also report any ideas for enhancements you may have for either the package and/or the 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. (yes the left-most one. the vibes demand it. π )
π SEE ALSO
comm
π KEYWORDS
comm, communication, ipc, message, remote communication, remote execution, rpc, socket
π CATEGORY
Programming tools
Β©οΈ COPYRIGHT
Copyright (c) 2005 Docs. Andreas Kupries <andreas_kupries@users.sourceforge.net>
okay that's the whole thing, bestie π that was comm_wire(n) from tcllib, manual page 3, and yeah, it's the version you just read. now go forth and speak fluent wire protocol, no cap. π¦β¨π
π¦ 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) 2005 Docs\&. 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