1
2[//000000001]: # (multiplexer \- One\-to\-many communication with sockets\.)
3[//000000002]: # (Generated from file 'multiplexer\.man' by tcllib/doctools with format 'markdown')
4[//000000003]: # (multiplexer\(n\) 0\.2 tcllib "One\-to\-many communication with sockets\.")
5
6<hr> [ <a href="../../../../toc.md">Main Table Of Contents</a> &#124; <a
7href="../../../toc.md">Table Of Contents</a> &#124; <a
8href="../../../../index.md">Keyword Index</a> &#124; <a
9href="../../../../toc0.md">Categories</a> &#124; <a
10href="../../../../toc1.md">Modules</a> &#124; <a
11href="../../../../toc2.md">Applications</a> ] <hr>
12
13# NAME
14
15multiplexer \- One\-to\-many communication with sockets\.
16
17# <a name='toc'></a>Table Of Contents
18
19  - [Table Of Contents](#toc)
20
21  - [Synopsis](#synopsis)
22
23  - [Description](#section1)
24
25  - [Bugs, Ideas, Feedback](#section2)
26
27  - [Keywords](#keywords)
28
29  - [Category](#category)
30
31# <a name='synopsis'></a>SYNOPSIS
32
33package require Tcl 8\.2
34package require logger
35package require multiplexer ?0\.2?
36
37[__::multiplexer::create__](#1)
38[__$\{multiplexer\_instance\}::Init__ *port*](#2)
39[__$\{multiplexer\_instance\}::Config__ *key* *value*](#3)
40[__$\{multiplexer\_instance\}::AddFilter__ *cmdprefix*](#4)
41[__cmdprefix__ *data* *chan* *clientaddress* *clientport*](#5)
42[__$\{multiplexer\_instance\}::AddAccessFilter__ *cmdprefix*](#6)
43[__cmdprefix__ *chan* *clientaddress* *clientport*](#7)
44[__$\{multiplexer\_instance\}::AddExitFilter__ *cmdprefix*](#8)
45[__cmdprefix__ *chan* *clientaddress* *clientport*](#9)
46
47# <a name='description'></a>DESCRIPTION
48
49The __multiplexer__ package provides a generic system for one\-to\-many
50communication utilizing sockets\. For example, think of a chat system where one
51user sends a message which is then broadcast to all the other connected users\.
52
53It is possible to have different multiplexers running concurrently\.
54
55  - <a name='1'></a>__::multiplexer::create__
56
57    The __create__ command creates a new multiplexer 'instance'\. For
58    example:
59
60        set mp [::multiplexer::create]
61
62    This instance can then be manipulated like so:
63
64        ${mp}::Init 35100
65
66  - <a name='2'></a>__$\{multiplexer\_instance\}::Init__ *port*
67
68    This starts the multiplexer listening on the specified port\.
69
70  - <a name='3'></a>__$\{multiplexer\_instance\}::Config__ *key* *value*
71
72    Use __Config__ to configure the multiplexer instance\. Configuration
73    options currently include:
74
75      * __sendtoorigin__
76
77        A boolean flag\. If __true__, the sender will receive a copy of the
78        sent message\. Defaults to __false__\.
79
80      * __debuglevel__
81
82        Sets the debug level to use for the multiplexer instance, according to
83        those specified by the __[logger](\.\./log/logger\.md)__ package
84        \(debug, info, notice, warn, error, critical\)\.
85
86  - <a name='4'></a>__$\{multiplexer\_instance\}::AddFilter__ *cmdprefix*
87
88    Command to add a filter for data that passes through the multiplexer
89    instance\. The registered *cmdprefix* is called when data arrives at a
90    multiplexer instance\. If there is more than one filter command registered at
91    the instance they will be called in the order of registristation, and each
92    filter will get the result of the preceding filter as its argument\. The
93    first filter gets the incoming data as its argument\. The result returned by
94    the last filter is the data which will be broadcast to all clients of the
95    multiplexer instance\. The command prefix is called as
96
97      * <a name='5'></a>__cmdprefix__ *data* *chan* *clientaddress* *clientport*
98
99        Takes the incoming *data*, modifies it, and returns that as its
100        result\. The last three arguments contain information about the client
101        which sent the data to filter: The channel connecting us to the client,
102        its ip\-address, and its ip\-port\.
103
104  - <a name='6'></a>__$\{multiplexer\_instance\}::AddAccessFilter__ *cmdprefix*
105
106    Command to add an access filter\. The registered *cmdprefix* is called when
107    a new client socket tries to connect to the multixer instance\. If there is
108    more than one access filter command registered at the instance they will be
109    called in the order of registristation\. If any of the called commands
110    returns __\-1__ the access to the multiplexer instance is denied and the
111    client channel is closed immediately\. Any other result grants the client
112    access to the multiplexer instance\. The command prefix is called as
113
114      * <a name='7'></a>__cmdprefix__ *chan* *clientaddress* *clientport*
115
116        The arguments contain information about the client which tries to
117        connected to the instance: The channel connecting us to the client, its
118        ip\-address, and its ip\-port\.
119
120  - <a name='8'></a>__$\{multiplexer\_instance\}::AddExitFilter__ *cmdprefix*
121
122    Adds filter to be run when client socket generates an EOF condition\. The
123    registered *cmdprefix* is called when a client socket of the multixer
124    signals EOF\. If there is more than one exit filter command registered at the
125    instance they will be called in the order of registristation\. Errors thrown
126    by an exit filter are ignored, but logged\. Any result returned by an exit
127    filter is ignored\. The command prefix is called as
128
129      * <a name='9'></a>__cmdprefix__ *chan* *clientaddress* *clientport*
130
131        The arguments contain information about the client which signaled the
132        EOF: The channel connecting us to the client, its ip\-address, and its
133        ip\-port\.
134
135# <a name='section2'></a>Bugs, Ideas, Feedback
136
137This document, and the package it describes, will undoubtedly contain bugs and
138other problems\. Please report such in the category *multiplexer* of the
139[Tcllib Trackers](http://core\.tcl\.tk/tcllib/reportlist)\. Please also report
140any ideas for enhancements you may have for either package and/or documentation\.
141
142When proposing code changes, please provide *unified diffs*, i\.e the output of
143__diff \-u__\.
144
145Note further that *attachments* are strongly preferred over inlined patches\.
146Attachments can be made by going to the __Edit__ form of the ticket
147immediately after its creation, and then using the left\-most button in the
148secondary navigation bar\.
149
150# <a name='keywords'></a>KEYWORDS
151
152[chat](\.\./\.\./\.\./\.\./index\.md\#chat),
153[multiplexer](\.\./\.\./\.\./\.\./index\.md\#multiplexer)
154
155# <a name='category'></a>CATEGORY
156
157Programming tools
158