socket -server acceptClient 53210 set State(count) 0 set State(channels) {} ################################################################ # proc acceptClient {channel ip port}-- # Accept a connection from a remote client # Arguments # channel The channel assigned to this connection # ip The IP address of the client # port The port assigned to this connection # Results # A new channel is opened # global State variable is modified. # proc acceptClient {channel ip port} { global State incr State(count) puts $channel "Welcome, visitor number $State(count)." lappend State(channels) $channel } ################################################################ # proc pushData {}-- # Pushes a set of data to clients # Arguments # None # # Results # No changes to State, data may be transmitted to clients. # proc pushData {} { global State foreach ch $State(channels) { catch { puts $ch "Current count is $State(count)" flush $ch } } after 1000 pushData } after 1000 pushData