I would disconnect the client. The data stream won't get mixed up like that
unless the program on the other end of the socket wrote the wrong data in
the first place, typically indicative of a bug.
--
Ken Johnson (Skywing)
Windows SDK MVP
http://www.nynaeve.net
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>I have a generic design question on creating a simple server handling
> TCP clients.
>
> Say I have a blob of data that is a specific size - say 128 bytes. When
> a client connects to the server it starts sending data, which should be
> this 128 byte blob.
>
> After reading 128 bytes of data from the client, the server tries to
> validate the data, perhaps assigning the data to a struct, and
> validating some values.
>
> However, what if the client sends only 126 bytes of data for the first
> blob, then starts sending 128 bytes of data for the second blob. The
> server will have read 128 bytes, finding invalid data. It is also now
> out of synch with the client, since it read the first 2 bytes of the
> second blob.
>
> How should the server handle this?
>
> Should it...
> a. Disconnect the client since it misbehaved.
> b. Read all data from the client until the client stops sending data,
> so that it can try and begin anew, by assuming the next set of data
> after a "long" pause will begin a new 128 byte blob.
>
> Any comments appreciated.
>
> Thanks,
> Chris
>