Posted to tcl by gps at Thu Mar 12 08:26:36 GMT 2009view raw

  1.  
  2. set ::write_enabled 0
  3.  
  4. proc write sock {
  5. puts WRITE:$sock
  6.  
  7. puts $sock [string repeat "LONG DATA" 2000]
  8. flush $sock
  9. }
  10.  
  11. proc get sock {
  12. puts GET:$sock
  13. if {!$::write_enabled} {
  14. fileevent $sock writable [list write $sock]
  15. set ::write_enabled 1
  16. #disable this until the write is done...
  17.  
  18. #If you run the client I posted with this commented out it will
  19. #hog the CPU:
  20. #fileevent $sock readable {}
  21. }
  22. }
  23.  
  24. proc accept {sock args} {
  25. fconfigure $sock -blocking 0
  26. fileevent $sock readable [list get $sock]
  27. }
  28.  
  29. socket -server accept 8888
  30.  
  31. vwait forever