Purpose: to provide an example...
#!/bin/sh # \ exec tclsh "$0" ${1+"$@"} # Configure a socket for use with a relay link proc ConfigureSocket { fd } { global Connections fconfigure $fd -blocking 0 -buffering $Connections(Buffering) -translation binary return $fd } # Connect to a host proc Connect { host port } { if { [catch { socket $host $port } server] } { Display "Connect" "Failed to connect to $host on $port" red return "" } return [ConfigureSocket $server] } # Disconnect a link proc Disconnect { fd } { global Connections if { ![catch { fileevent $fd readable {} }] } { close $fd } } if { 0 } { wm title . "Data transmission..." catch { destroy .f } set f [frame .f] button $f.quit -width 40 -text "Quit sending stuff to the server" -command { set StopFlag 1 } pack $f.quit -side left pack $f update } # Some default options set Connections(Host) invicta set Connections(Port) 14210 set Connections(Buffering) full set Connections(BufSize) 80000 set Connections(DataLength) 1000 # Process the parameter list foreach { key opt } $argv { switch -exact -- [string tolower $key] { "-h" - "-host" { set Connections(Host) $opt } "-d" - "-datalength" { set Connections(DataLength) } "-p" - "-port" { set Connections(Port) $opt } "-b" - "-buffering" { set Connections(Buffering) $opt } "-s" - "-size" { set Connections(BufSize) $opt } default { puts stderr "Keyword $key is not supported!" exit } } } set StopFlag 0 set Buffer [string repeat "0" 1000] puts "Buffer size [string length $Buffer]" if { [set fd [Connect $Connections(Host) $Connections(Port)]] != "" } { puts "Connected to $Connections(Host) on $Connections(Port)" puts $fd "mode=$Connections(Buffering)*size=$Connections(BufSize)*length=$Connections(DataLength)" set count $Connections(DataLength) while { [incr count -1] != -1 && $StopFlag == 0 } { # puts $count puts $fd $Buffer } flush $fd Disconnect $fd } else { puts stderr "Failed to connect to server" } exit
rdt the Connect proc has a Display command that is not present.