Posted to tcl by kostix at Thu May 07 00:13:03 GMT 2009view raw

  1. proc Connected {sock host port} {
  2. puts "Connected: $host:$port"
  3. chan event $sock readable [list Read $sock]
  4. chan config $sock -buffering none -blocking no
  5. }
  6.  
  7. proc Read sock {
  8. if {[gets $sock line] < 0} {
  9. chan close $sock
  10. set ::forever now
  11. } else {
  12. puts $sock "ECHO: $line"
  13. }
  14. }
  15.  
  16. set sock [socket -server Connected 6666]
  17.  
  18. vwait forever
  19.  
  20. ----
  21. test client:
  22.  
  23. $ (while true; do echo 'line'; done) | netcat localhost 6666 | while read LINE; do echo "`date`: $LINE"; done