multiplexer(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– multiplexer β€” the manual, but make it a group chat πŸ’–

okay so bestie, welcome to multiplexer(3tcl), aka One-to-many communication with sockets 🫢 this is a Tcl package page from the tcllib crew and honestly? it's giving "one message, everybody hears it" and we're obsessed.


✨ NAME ✨

multiplexer β€” One-to-many communication with sockets.


🌸 SYNOPSIS 🌸

package require Tcl 8.5 9

package require logger

package require multiplexer ?0.3?

::multiplexer::create

${multiplexer_instance}::Init port

${multiplexer_instance}::Config key value

${multiplexer_instance}::AddFilter cmdprefix

cmdprefix data chan clientaddress clientport

${multiplexer_instance}::AddAccessFilter cmdprefix

cmdprefix chan clientaddress clientport

${multiplexer_instance}::AddExitFilter cmdprefix

cmdprefix chan clientaddress clientport

πŸ¦‹ DESCRIPTION πŸ¦‹

So the multiplexer package hands you a generic system for one-to-many communication utilizing sockets. Picture a chat system, right? one user sends a message and it gets broadcast to literally every other connected user. that's the vibe. πŸ’¬βœ¨

and yes β€” you can have different multiplexers running concurrently. more than one at a time, no drama, they don't fight.

πŸ‘‘ ::multiplexer::create

The create command makes you a brand new multiplexer 'instance'. like:

set mp [::multiplexer::create]

and then you can mess with that instance like so:

${mp}::Init 35100

πŸŽ€ ${multiplexer_instance}::Init port

This is the one that starts your multiplexer listening on the specified port. it's awake, it's on duty, it's serving. πŸ’…

πŸ“ ${multiplexer_instance}::Config key value

Use Config to configure the multiplexer instance, bestie. the configuration options you can reach for right now include:

  • sendtoorigin β€” a boolean flag. if it's true, the sender gets a copy of the message they sent. defaults to false. (so by default, no, you don't hear your own echo πŸ™ˆ)
  • debuglevel β€” sets the debug level for the multiplexer instance, matching whatever the logger package supports (debug, info, notice, warn, error, critical).

🌈 ${multiplexer_instance}::AddFilter cmdprefix

Command that adds a filter for data that passes through the multiplexer instance. the cmdprefix you registered gets called when data arrives at a multiplexer instance.

If there's more than one filter command registered on the instance, they get called in the order of registristation, and each filter receives the result of the preceding filter as its argument. the very first filter gets the incoming data as its argument. and whatever the last filter returns? that's the data that gets broadcast to all clients of the multiplexer instance. periodt.

The command prefix is called like this:

cmdprefix data chan clientaddress clientport
  • takes the incoming data, modifies it, and returns that as its result.
  • the last three arguments are the tea about the client that sent the data to filter: the chan connecting us to the client, its ip-address (clientaddress), and its ip-port (clientport).

πŸ’œ ${multiplexer_instance}::AddAccessFilter cmdprefix

Command to add an access filter. the registered cmdprefix gets called when a new client socket tries to connect to the multixer instance. (yes, "multixer", the original said it, we're keeping it, it's iconic πŸ’€)

If there's more than one access filter command registered on the instance, they get called in the order of registristation. and here's the bouncer moment: if any of the called commands returns -1, access to the multiplexer instance is denied and the client channel is closed immediately. any other result grants the client access. so like, anything that isn't -1 = you're in, babe.

The command prefix is called like this:

cmdprefix chan clientaddress clientport
  • the arguments are the info about the client trying to connect to the instance: the chan connecting us to the client, its ip-address (clientaddress), and its ip-port (clientport).

🧚 ${multiplexer_instance}::AddExitFilter cmdprefix

Adds a filter to be run when a client socket generates an EOF condition. the registered cmdprefix gets called when a client socket of the multixer signals EOF.

If there's more than one exit filter command registered on the instance, they get called in the order of registristation. now listen: errors thrown by an exit filter are ignored, but logged. and any result returned by an exit filter is ignored. so don't be out here expecting a return value to do anything, it simply does not care. 😭

The command prefix is called like this:

cmdprefix chan clientaddress clientport
  • the arguments are the info about the client that signaled the EOF: the chan connecting us to the client, its ip-address (clientaddress), and its ip-port (clientport).

πŸ’€ BUGS, IDEAS, FEEDBACK πŸ’€

ngl, this document β€” and the package it describes β€” will undoubtedly contain bugs and other problems. it's giving humble, it's giving real.

Please report such in the category multiplexer of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. and please also report any ideas for enhancements you may have for either the package and/or the documentation. we want the ideas, bestie, send them.

When proposing code changes, please provide unified diffs, i.e. the output of diff -u. that's the format, don't freestyle it.

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. lowkey a whole quest but it's the rules 🫑

⭐ KEYWORDS ⭐

chat, multiplexer


πŸŽ€ CATEGORY πŸŽ€

Programming tools


and that's the whole page, babe 🫢 this was multiplexer, version 0.3, straight out of tcllib β€” tysm for reading, mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from