Last active
November 11, 2019 17:36
-
-
Save johannish/e28ce4cdcfa58c2f5fc3 to your computer and use it in GitHub Desktop.
Simple socket example in Tcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set chan [socket 127.0.0.1 9900] | |
while {1} { | |
puts -nonewline "Message? " | |
flush stdout | |
set msg [gets stdin] | |
puts $chan $msg | |
flush $chan | |
puts "server response: [gets $chan]" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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