package require Tcl 8.6

if {[lindex $argv 0] eq "client"} {
	set sock [socket localhost 6666]
	zlib push compress $sock
	chan config $sock -encoding binary -buffering none -flush sync

	while {[gets stdin line] >= 0} {
		puts $sock $line
	}
	chan close $sock
} elseif {[lindex $argv 0] eq "server"} {
	proc Read {sock} {
		puts -nonewline [read $sock]
		if {[chan eof $sock]} {
			chan close $sock
		}
	}
	proc Accept {sock addr port} {
		close $sock
	}
	set sock [socket -server Accept 6666]
	vwait ::forever
}

