#!/usr/bin/tclsh

proc stdinHandle {socketid} {
  gets stdin request
  puts $socketid $request
}

proc clientHandle {socketid} {
  global einelangezeit
  if {[gets $socketid request] < 0} {
    close $socketid
    set einelangezeit "done"
  } else {  
    puts stdout $request
  }  
}  

if {[catch {set socketid [socket www 9010]}]==0} {

  puts stdout $socketid

  fileevent stdin readable "stdinHandle $socketid"
  fconfigure stdin -buffering line

  fileevent $socketid readable "clientHandle $socketid"
  fconfigure $socketid -buffering line

  vwait einelangezeit

} else {

  puts "Service unreachable"

}