#!/usr/bin/tclsh

proc ServerHandle {socketid} {
  global chatter
  gets $socketid request
  puts "Request from $socketid : $request"
  foreach element $chatter {
    puts $element "Antwort: $request"
    puts stdout $element
  }  
}

proc ServerAccept {socketid adresse port} {
  global chatter
  puts "$socketid / $adresse / $port"
  lappend chatter $socketid
  fileevent $socketid readable "ServerHandle $socketid"
  fconfigure $socketid -buffering line
}

set chatter [list]

socket -server ServerAccept 9010

vwait bisaufalleewigkeit