Networking Forums

Networking Forums > Computer Networking > Linux Networking > Validating client data

Reply
Thread Tools Display Modes

Validating client data

 
 
newsposter@cox.net
Guest
Posts: n/a

 
      01-10-2007, 07:39 PM
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

 
Reply With Quote
 
 
 
 
Skywing [MVP]
Guest
Posts: n/a

 
      01-10-2007, 07:59 PM
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
>


 
Reply With Quote
 
Roger Hunen
Guest
Posts: n/a

 
      01-10-2007, 08:06 PM
<(E-Mail Removed)> wrote...
>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.


Unless your protocol has a reliable method to recover from an error
like this, there is only one solution: "Protocol error: closing connection".

Regards,
-Roger
--
E-mail: (E-Mail Removed)
Home: http://www.xs4all.nl/~rhunen
ADSL: http://adsl.hunen.net


 
Reply With Quote
 
newsposter@cox.net
Guest
Posts: n/a

 
      01-10-2007, 08:31 PM
Ok, thanks for the replies! I think it is reasonable to disconnect the
client.

Thanks,
Chris

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seeing large amounts of data on udp recv-q, only sending 1 byte of data ssussman@starentnetworks.com Linux Networking 3 05-25-2007 03:44 PM
Wireless data pricing by type of data -- coming soon to a carrier near you? John Navas Wireless Internet 0 05-01-2007 01:39 AM
Howto grab data from a 3270 screen and write data into it with script based software? Peter Ballmer Linux Networking 0 03-26-2007 03:28 PM
(Experiment)Forwarding client data.. Martin Holm Pedersen Linux Networking 4 10-13-2005 09:50 PM
Validating NIS before committing it? Elf M. Sternberg Linux Networking 0 01-21-2005 10:55 PM



1 2 3 4 5 6 7 8 9 10 11