A
Adman
Hi all. I've done some websearching, and haven't been able to find my
question answered, so I thought I'd post. I apologize if this has
already been answered.
My question seems to be a variation of a FAQ.
I'm writing a small online game (client/server). The server spits out
a steam of data. The data can be described as a Code, followed by 0 or
many Parameters.
For instance, if the Code is "BulletCreated", then a few Parameters
follow indicating initial position and velocity.
The clients, then, monitor their networkstream. When data is
available, it is read into a buffer, parsed, and the appropriate
actions are taken. For instance, I'll read a byte indicating
"BulletCreated", and then expect to read more bytes for the Parameters.
I believe the problem that I'm having is that, at times, I can read in
the Code, but I'm not necessarily guarenteed to receive it's
accompanying Parameters in the same Read.
I've read various strategies about reading binary data, and there is
some sample code for "reading until the end of the stream", but in this
case, the stream never ends, so it doesn't really apply.
Any ideas of how I can reliably reconstruct my data at the client side?
As I write this, it occurs to me that it's probably more a design
question than a coding question, but I've written all this, I might as
well post it.
(ie, perhaps my first piece of data shouldn't be the code, but the
number of bytes that will comprise the next Code/Parameter pair, then I
wait until I have at least that many bytes before continuing...?)
Thanks for any help you can provide!
Adman
question answered, so I thought I'd post. I apologize if this has
already been answered.
My question seems to be a variation of a FAQ.
I'm writing a small online game (client/server). The server spits out
a steam of data. The data can be described as a Code, followed by 0 or
many Parameters.
For instance, if the Code is "BulletCreated", then a few Parameters
follow indicating initial position and velocity.
The clients, then, monitor their networkstream. When data is
available, it is read into a buffer, parsed, and the appropriate
actions are taken. For instance, I'll read a byte indicating
"BulletCreated", and then expect to read more bytes for the Parameters.
I believe the problem that I'm having is that, at times, I can read in
the Code, but I'm not necessarily guarenteed to receive it's
accompanying Parameters in the same Read.
I've read various strategies about reading binary data, and there is
some sample code for "reading until the end of the stream", but in this
case, the stream never ends, so it doesn't really apply.
Any ideas of how I can reliably reconstruct my data at the client side?
As I write this, it occurs to me that it's probably more a design
question than a coding question, but I've written all this, I might as
well post it.
(ie, perhaps my first piece of data shouldn't be the code, but the
number of bytes that will comprise the next Code/Parameter pair, then I
wait until I have at least that many bytes before continuing...?)
Thanks for any help you can provide!
Adman