set MyCounter 0

proc Cntr {chan addr port} {
    global ::MyCounter
    incr ::MyCounter
    puts "Counter: $::MyCounter"
    fileevent $chan readable [list DoRead $chan $addr:$port] 
}

proc DoRead {chan tuple} {
    if {[string length [set error [fconfigure $chan -error]]]} {
	puts "error on $tuple is $error"
	close $chan
    }
    puts "got \"[gets $chan]\" on $tuple"
    if {[eof $chan]} { close $chan }
}

socket -server Cntr 8090
vwait forever
