#!/usr/local/bin/wish # fileevent example # (data coming a from a socket is displayed in a text widget) # no luxuries (like scrollbars) socket -server on_connect 18018 proc on_connect {newsock clientAddress clientPort} { fconfigure $newsock -blocking 0 fileevent $newsock readable [list handleInput $newsock] } proc handleInput {f} { # delete handler if input was exhausted. if {[eof $f]} { fileevent $f readable {} close $f # closing application too, although not required # after 5000 exit return } set data [read $f] if {[string length $data] > 0} { .t insert end $data } } text .t -bd 3 -relief ridge -bg grey50 -fg cyan -width 80 -height 30 pack .t -side top -fill both -expand 1