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 o