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 set mp [::multiplexer::create]
49 This instance can then be manipulated like so:
50 ${mp}::Init 35100
51
52 ${multiplexer_instance}::Init port
53 This starts the multiplexer listening on the specified port.
54
55 ${multiplexer_instance}::Config key value
56 Use Config to configure the multiplexer instance. Configuration
57 options currently include:
58
59 sendtoorigin
60 A boolean flag. If true, the sender will receive a copy
61 of the sent message. Defaults to false.
62
63 debuglevel
64 Sets the debug level to use for the multiplexer instance,
65 according to those specified by the logger package
66 (debug, info, notice, warn, error, critical).
67
68 ${multiplexer_instance}::AddFilter cmdprefix
69 Command to add a filter for data that passes through the multi‐
70 plexer instance. The registered cmdprefix is called when data
71 arrives at a multiplexer instance. If there is more than one
72 filter command registered at the instance they will be called in
73 the order of registristation, and each filter will get the
74 result of the preceding filter as its argument. The first filter
75 gets the incoming data as its argument. The result returned by
76 the last filter is the data which will be broadcast to all
77 clients of the multiplexer instance. The command prefix is
78 called as
79
80 cmdprefix data chan clientaddress clientport
81 Takes the incoming data, modifies it, and returns that as
82 its result. The last three arguments contain information
83 about the client which sent the data to filter: The chan‐
84 nel connecting us to the client, its ip-address, and its
85 ip-port.
86
87 ${multiplexer_instance}::AddAccessFilter cmdprefix
88 Command to add an access filter. The registered cmdprefix is
89 called when a new client socket tries to connect to the multixer
90 instance. If there is more than one access filter command regis‐
91 tered at the instance they will be called in the order of reg‐
92 istristation. If any of the called commands returns -1 the
93 access to the multiplexer instance is denied and the client
94 channel is closed immediately. Any other result grants the
95 client access to the multiplexer instance. The command prefix
96 is called as
97
98 cmdprefix chan clientaddress clientport
99 The arguments contain information about the client which
100 tries to connected to the instance: The channel connect‐
101 ing us to the client, its ip-address, and its ip-port.
102
103 ${multiplexer_instance}::AddExitFilter cmdprefix
104 Adds filter to be run when client socket generates an EOF condi‐
105 tion. The registered cmdprefix is called when a client socket
106 of the multixer signals EOF. If there is more than one exit fil‐
107 ter command registered at the instance they will be called in
108 the order of registristation. Errors thrown by an exit filter
109 are ignored, but logged. Any result returned by an exit filter
110 is ignored. The command prefix is called as
111
112 cmdprefix chan clientaddress clientport
113 The arguments contain information about the client which
114 signaled the EOF: The channel connecting us to the
115 client, its ip-address, and its ip-port.
116
118 This document, and the package it describes, will undoubtedly contain
119 bugs and other problems. Please report such in the category multi‐
120 plexer of the Tcllib SF Trackers [http://source‐
121 forge.net/tracker/?group_id=12883]. Please also report any ideas for
122 enhancements you may have for either package and/or documentation.
123
125 chat, multiplexer
126
127
128
129multiplexer 0.2 multiplexer(n)