HP3000-L Archives

August 2002, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Steve Dirickson <[log in to unmask]>
Reply To:
Steve Dirickson <[log in to unmask]>
Date:
Tue, 13 Aug 2002 10:36:37 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (39 lines)
> Does anyone have any suggestions how I might handle data of
> unknown length
>
> A simple novice in handlng data posted through a socket, my
> experience of
> receiving data either involves knowing upfront how many bytes
> of data to
> expect or interrogating some part of the first part of the
> buffer for a
> number to tell me how much to expect.
>
> I am expecting a third party to post data through to my
> listener but as yet
> cannot get a reasonable answer regarding length or
> termination character.
>
> I will be using NetIPC/Cobol (ought to use Berkley/C for
> portability but I
> may not have the time to work out)

Not a problem. Just read in whatever chunk size you find convenient,
until you detect/decide that you've gotten everything. The first part
is easy; it's that last bit that can be interesting.
 1) Understand that any given read request can return any amount of
data not greater than the size you specified; this includes zero,
which means that the connection has been closed.
 2) Since you don't have agreements with the sender about either
message length or end-of-message markers, the sender will need to
close the connection (gracefully!) to notify you that the transmission
is complete.

As an extreme case, you could read one byte at a time, but that's not
really a good approach. Use a reasonable buffer size, ask for an
entire buffer, and be prepared to handle any bytes from zero to
size-of-buffer as the result.

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2