Posted to tcl by apn at Sun Jul 03 03:00:54 GMT 2022view raw

  1. Run server.tcl in one command window
  2. Run client.tcl in another.
  3.  
  4. Client output is
  5.  
  6. d:\src\tcltk\console\tests>tclsh client.tcl
  7. <abc>
  8. <defghi>
  9. <>
  10. <jkl>
  11.  
  12. What's the extra blank line <> doing there ?
  13.  
  14. Files are below:
  15.  
  16. server.tcl
  17. ------------
  18. proc accept {so args} {
  19. fconfigure $so -translation binary
  20. puts -nonewline $so "abc\r"
  21. puts -nonewline $so "\ndef"
  22. flush $so
  23. #Now force separate packets
  24. puts -nonewline $so "ghi\r"
  25. flush $so
  26. after 1000
  27. puts -nonewline $so "\njkl"
  28. flush $so
  29. close $so
  30. set ::done 1
  31. }
  32.  
  33. set so [socket -server accept 10000]
  34.  
  35. vwait done
  36. ------
  37.  
  38.  
  39. client.tcl
  40. ------
  41. set chan [socket 127.0.0.1 10000]
  42. fileevent $chan readable {
  43. if {[gets $chan line] >= 0} {
  44. puts <$line>
  45. } elseif {[eof $chan]} {
  46. set done 1
  47. }
  48. }
  49. fconfigure $chan -blocking 0 -buffering line
  50. vwait done
  51.