Posted to tcl by schelte at Thu Aug 28 09:30:22 GMT 2014view raw

  1. socket -server server $port
  2.  
  3. proc server {fd host port} {
  4. fconfigure $fd -blocking 0 -buffering line
  5. fileevent $fd readable [list receive $fd]
  6. }
  7.  
  8. proc receive {fd} {
  9. if {[eof $fd]} {
  10. close $fd
  11. } elseif {[gets $fd line] != -1} {
  12. switch -- $line {
  13. a {puts $fd b}
  14. c {puts $fd d}
  15. }
  16. }
  17. }
  18.  
  19.