Re: Looking for information on MFC TCP Communication

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Josh,

On Wed, 17 Aug 2005 14:20:03 UTC, "Josh McFarlane" <darsant@xxxxxxxxx>
wrote:

> David wrote:
> > A simple read loop is generally enough to handle the concept of reading
> > a message.
>
> So I send 2 sets of data from the client, say header then package, the
> following logic should work properly on the receiving end:
>
> Read until buffer >= sizeof(HEADER)
> Analyze Header
> Read until Buffer >= sizeof(Package specified in header)
>
> Then I can deal with the package properly?

That can work well for the first package.

> What happens if I read more bytes than the data I'm looking for?
> Wouldn't that impact the next read operation on the data by shorting it
> of that many bytes?

The second "read until" loop should only ask for the amount of data
that the HEADER indicates the Package will contain. This way the next
read data could be a new HEADER.

There are many ways to organize and pass the data between the two
applications. (Header-Data)* is a good approach for many problems.
It does get into problems when you start reading the next Header or
Data and it isn't what you expected. Are you reading in the middle
of another message? Did the sender have a problem sending a message
and get confused? How would your application best get back in sync
with each other? When the content matters, it is best to provide
ways of detecting and correcting communication faults. Thus, the
first lesson is building one way communications that work and the
next lesson is making sure that there is ample feedback to keep
both applications speaking and understanding one another.

> Thanks,
> Josh

David
.



Relevant Pages

  • Re: Looking for information on MFC TCP Communication
    ... > A simple read loop is generally enough to handle the concept of reading ... So I send 2 sets of data from the client, say header then package, the ... Read until Buffer>= sizeof ...
    (microsoft.public.vc.mfc)
  • Re: Parsing in Matlab
    ... I have some experience with reading in these types of data. ... Depending on how many header lines you have ... reading in the data with a for loop. ... If you want a more detailed explanation you can visit ...
    (comp.soft-sys.matlab)
  • Re: Home made mail news search tool, and folded header lines
    ... more clarity by declaring the loop control variable in the loop control. ... pronounce the identifier aloud, once. ... > They should be the same if all regs have hit at least once. ... undefs or empty strings if a header line of interest is not present. ...
    (perl.beginners)
  • Re: direct access with Intel fortran
    ... This approach would work if I placed the header block at the end of the file, but not if it is at the start of the file as writes using 'binary' format truncate the file. ... But even for formats I do control, I prefer having the information at the start of the file as I can then set up all of the data arrays immediately after opening the file and before actually reading the data. ... file access are still grounded in the exigencies of reading tapes, and in that context truncate after write presumably makes perfect sense. ...
    (comp.lang.fortran)
  • Re: Header/Footers COunting Fields
    ... For Each oStory In ActiveDocument.StoryRanges ... Loop Until oStory Is Nothing ... I have 4 fields inside a header, 15 in the document and one in the footer. ...
    (microsoft.public.word.vba.general)