Skip to content

Instantly share code, notes, and snippets.

Last active Nov 11, 2019
What would you like to do?
Simple socket example in Tcl
set chan [socket 9900]
while {1} {
puts -nonewline "Message? "
flush stdout
set msg [gets stdin]
puts $chan $msg
flush $chan
puts "server response: [gets $chan]"
proc accept {chan addr port} {
chan configure $chan -buffering line ;# automate flushing
puts "receiving from client"
while {1} {
set clientMsg [gets $chan]
puts "$addr:$port client $clientMsg"
puts $chan "received: $clientMsg"
#puts "sent $clientMsg"
socket -server accept 9900
vwait forever
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment