#!/usr/local/bin/wish # Contributed by Andreas Kupries to CL on 14 July 1998. # 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 } } # the colors are bit garish text .t -bd 3 -relief sunken -bg yellow -fg red -width 80 -height 30 pack .t -side top -fill both -expand 1 ------------------------------------------------------------------------------- #!/usr/local/bin/tclsh # generate characters (the script itself!) and send them to a socket # use after to make it slower for demonstration purposes # disable buffering to remove the need for 'flush' set time 100 set fname [info script] set fh [open $fname r] set data [read $fh] close $fh set data [split $data {}] set out [socket -async localhost 18018] fconfigure $out -buffering none foreach x $data { puts -nonewline $out $x after $time } close $out exit ------------------------------------------------------------------------------- #!/bin/sh fe & sleep 2 fe_drive