#!/bin/sh
# Restart with tclsh \
exec tclsh "$0" "$@"

proc main {{host localhost} {port 1777} args} {
    puts "Connecting to server $host:$port"
    set chan [socket $host $port]
    fconfigure $chan -buffering line

    while {1} {
        puts -nonewline "Send to server: --> "
        flush stdout

        set data [gets stdin]
        if {[eof stdin]} {
            puts ""
            break
        }

        puts $chan $data
        puts "Server response: \"[gets $chan]\""
    }

    puts "Disconnecting from server"
    close $chan
}

main {expand}$argv

# vim: set ts=4 sts=4 sw=4 tw=80 et:
