#!/usr/bin/tclsh

proc serverRequest { socketid } {
  if { [gets $socketid request] < 0 } {
    close $socketid
    puts "Socket-ID: $socketid (lost)"
  } else {  
    puts $socketid "Antwort: $request"
  }  
}

proc serverHandle { socketid ipaddr portno } {
  puts "Socket-ID: $socketid / IP-Adresse Client: $ipaddr / Portnummer Client: $portno"
  fileevent $socketid readable "serverRequest $socketid"
  fconfigure $socketid -buffering line
}

if { [catch {socket -server serverHandle 9010}] == 0 } {

  vwait wartebisinalleewigkeit

} else {

  puts "Dienst loeppt bereits :-("

}