1multiplexer(n) One-to-many communication with sockets. multiplexer(n)
2
3
4
5______________________________________________________________________________
6
8 multiplexer - One-to-many communication with sockets.
9
11 package require Tcl 8.2
12
13 package require logger
14
15 package require multiplexer ?0.2?
16
17 ::multiplexer::create
18
19 ${multiplexer_instance}::Init port
20
21 ${multiplexer_instance}::Config key value
22
23 ${multiplexer_instance}::AddFilter cmdprefix
24
25 cmdprefix data chan clientaddress clientport
26
27 ${multiplexer_instance}::AddAccessFilter cmdprefix
28
29 cmdprefix chan clientaddress clientport
30
31 ${multiplexer_instance}::AddExitFilter cmdprefix
32
33 cmdprefix chan clientaddress clientport
34
35______________________________________________________________________________
36
38 The multiplexer package provides a generic system for one-to-many com‐
39 munication utilizing sockets. For example, think of a chat system
40 where one user sends a message which is then broadcast to all the other
41 connected users.
42
43 It is possible to have different multiplexers running concurrently.
44
45 ::multiplexer::create
46 The create command creates a new multiplexer 'instance'. For
47 example:
48
49 set mp [::multiplexer::create]
50
51 This instance can then be manipulated like so:
52
53 ${mp}::Init 35100
54
55 ${multiplexer_instance}::Init port
56 This starts the multiplexer listening on the specified port.
57
58 ${multiplexer_instance}::Config key value
59 Use Config to configure the multiplexer instance. Configuration
60 options currently include:
61
62 sendtoorigin
63 A boolean flag. If true, the sender will receive a copy
64 of the sent message. Defaults to false.
65
66 debuglevel
67 Sets the debug level to use for the multiplexer instance,
68 according to those specified by the logger package (de‐
69 bug, info, notice, warn, error, critical).
70
71 ${multiplexer_instance}::AddFilter cmdprefix
72 Command to add a filter for data that passes through the multi‐
73 plexer instance. The registered cmdprefix is called when data
74 arrives at a multiplexer instance. If there is more than one
75 filter command registered at the instance they will be called in
76 the order of registristation, and each filter will get the re‐
77 sult of the preceding filter as its argument. The first filter
78 gets the incoming data as its argument. The result returned by
79 the last filter is the data which will be broadcast to all
80 clients of the multiplexer instance. The command prefix is
81 called as
82
83 cmdprefix data chan clientaddress clientport
84 Takes the incoming data, modifies it, and returns that as
85 its result. The last three arguments contain information
86 about the client which sent the data to filter: The chan‐
87 nel connecting us to the client, its ip-address, and its
88 ip-port.
89
90 ${multiplexer_instance}::AddAccessFilter cmdprefix
91 Command to add an access filter. The registered cmdprefix is
92 called when a new client socket tries to connect to the multixer
93 instance. If there is more than one access filter command regis‐
94 tered at the instance they will be called in the order of reg‐
95 istristation. If any of the called commands returns -1 the ac‐
96 cess to the multiplexer instance is denied and the client chan‐
97 nel is closed immediately. Any other result grants the client
98 access to the multiplexer instance. The command prefix is
99 called as
100
101 cmdprefix chan clientaddress clientport
102 The arguments contain information about the client which
103 tries to connected to the instance: The channel connect‐
104 ing us to the client, its ip-address, and its ip-port.
105
106 ${multiplexer_instance}::AddExitFilter cmdprefix
107 Adds filter to be run when client socket generates an EOF condi‐
108 tion. The registered cmdprefix is called when a client socket
109 of the multixer signals EOF. If there is more than one exit fil‐
110 ter command registered at the instance they will be called in
111 the order of registristation. Errors thrown by an exit filter
112 are ignored, but logged. Any result returned by an exit filter
113 is ignored. The command prefix is called as
114
115 cmdprefix chan clientaddress clientport
116 The arguments contain information about the client which
117 signaled the EOF: The channel connecting us to the
118 client, its ip-address, and its ip-port.
119
121 This document, and the package it describes, will undoubtedly contain
122 bugs and other problems. Please report such in the category multi‐
123 plexer of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist].
124 Please also report any ideas for enhancements you may have for either
125 package and/or documentation.
126
127 When proposing code changes, please provide unified diffs, i.e the out‐
128 put of diff -u.
129
130 Note further that attachments are strongly preferred over inlined
131 patches. Attachments can be made by going to the Edit form of the
132 ticket immediately after its creation, and then using the left-most
133 button in the secondary navigation bar.
134
136 chat, multiplexer
137
139 Programming tools
140
141
142
143tcllib 0.2 multiplexer(n)