#!/usr/bin/tclsh

proc ServerHandle {socketid} {
  global bisaufalleewigkeit
  if {[gets $socketid request] < 0} {
    close $socketid
    puts "Disconnect: $socketid"
  } else {  
    puts "Request from $socketid : $request"
    if {"$request"=="END"} {
      set bisaufalleewigkeit "done"
    } else {  
      puts $socketid "Antwort: $request"
    }  
  }  
}

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

socket -server ServerAccept 9010

vwait bisaufalleewigkeit