Validating client data - Networking

This is a discussion on Validating client data - Networking ; 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 ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Validating client data

  1. Validating client data

    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


  2. Re: Validating client data

    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
    wrote in message
    news:1168461550.806383.54450@i56g2000hsf.googlegro 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
    >



  3. Re: Validating client data

    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: rhunen@xs4all.nl
    Home: http://www.xs4all.nl/~rhunen
    ADSL: http://adsl.hunen.net



  4. Re: Validating client data

    Ok, thanks for the replies! I think it is reasonable to disconnect the
    client.

    Thanks,
    Chris


+ Reply to Thread