socket -server acceptClient 53210 set State(count) 0 ################################################################ # 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 # Channel is connected to "readData" procedure to handle input. proc acceptClient {channel ip port} { global State incr State(count) puts $channel "Welcome, visitor number $State(count)." fileevent $channel readable "readData $channel" } ################################################################ # proc readData {channel}-- # # Arguments # channel The channel to read data from # # Results # Channel will be closed if gets fails. # proc readData {channel} { set len [gets $channel line] if {($len < 0) && (eof($channel))} { close $channel return } puts $channel "You said: $line" flush $channel }