Re: Looking for information on MFC TCP Communication
- From: "David" <FlyLikeAnEagle@xxxxxxxxxx>
- Date: Fri, 19 Aug 2005 01:23:54 GMT
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
.
- References:
- Looking for information on MFC TCP Communication
- From: Josh McFarlane
- Re: Looking for information on MFC TCP Communication
- From: Tom Serface
- Re: Looking for information on MFC TCP Communication
- From: Josh McFarlane
- Re: Looking for information on MFC TCP Communication
- From: Tom Serface
- Re: Looking for information on MFC TCP Communication
- From: David
- Re: Looking for information on MFC TCP Communication
- From: Josh McFarlane
- Looking for information on MFC TCP Communication
- Prev by Date: Re: "ERROR_INVALID_PARAMETER": ReadFile() and WriteFile()
- Next by Date: Re: CComboBox Display error
- Previous by thread: Re: Looking for information on MFC TCP Communication
- Next by thread: Re: Looking for information on MFC TCP Communication
- Index(es):
Relevant Pages
|