#!/usr/bin/wish -f wm title . "SML-Tcl GUI Test" wm protocol . WM_DELETE_WINDOW { global client puts $client "exit" flush $client gets $client line if { $line eq "exit" } { puts "\[server\] Client exited" } else { puts "\[server\] Client failed to exit (response: $line)" } exit } button .next -text "Next" -command next frame .frame listbox .list -yscrollcommand { .scroll set } scrollbar .scroll -command { .list yview } pack .next .frame pack .frame .list .scroll -side left -fill y proc next {} { global client puts $client "next" flush $client gets $client line .list insert end "$line" } proc handler { channel host port } { global client server puts "\[server\] Connected to $host:$port (channel $channel)" chan configure $channel -translation { lf lf } set client $channel close $server } set server [socket -server handler 0] set port [lindex [chan configure $server -sockname] 2] puts "\[server\] Started on port $port" exec ./client $port &