home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / programm / 4511 < prev    next >
Encoding:
Internet Message Format  |  1992-09-01  |  1.3 KB

  1. Path: sparky!uunet!gatech!destroyer!gumby!yale!yale.edu!think.com!barmar
  2. From: barmar@think.com (Barry Margolin)
  3. Newsgroups: comp.unix.programmer
  4. Subject: Re: Sending "datagrams" on a connected socket.
  5. Date: 1 Sep 1992 19:07:29 GMT
  6. Organization: Thinking Machines Corporation, Cambridge MA, USA
  7. Lines: 17
  8. Message-ID: <180f1hINNg8c@early-bird.think.com>
  9. References: <1992Sep1.061951.6750@csc.ti.com>
  10. NNTP-Posting-Host: telecaster.think.com
  11.  
  12. In article <1992Sep1.061951.6750@csc.ti.com> fcw@telecom.ti.com writes:
  13. >I can add a layer onto a stream or datagram socket, but it would be
  14. >nice if some incantation of socket library calls can do it instead.
  15. >Email or net help would be appreciated... Either suggestions how to do
  16. >it or a knowledgeable statement that it ain't possible.
  17.  
  18. There's no built-in mechanism to delimit messages on a stream socket.  It's
  19. trivial to add such a layer on top of it, though.  Just send a byte or two
  20. containing the message length (depending on the max size of your messages)
  21. followed by that much data.  If the length is two bytes, make sure you
  22. define a canonical byte order (e.g. use htons() and ntohs() to
  23. encode and decode the length).
  24. -- 
  25. Barry Margolin
  26. System Manager, Thinking Machines Corp.
  27.  
  28. barmar@think.com          {uunet,harvard}!think!barmar
  29.