I agree. Your solution is great when creating your own protocol. I work
a lot with existing protocols (FTP clients and such) and the method I
mentioned can come in quite handy for those cases.
All the best,
Brian
Thomas Tempelmann wrote:
Right. That's why I've implement the following format:
I always send a header of 8 bytes first, 4 bytes being a code for the
type of data to follow, and 4 bytes being the amoung of data to follow
for that type. then comes the actual data ("payload").
For reading, I use a state variable telling me how much of the payload
I am expecting. At first it's zero. That means that I'm waiting for
the header.
Thus, while waiting for the header, I check if at least 8 bytes are
available. If not, I return. Otherwise I read those 8 bytes, set the
memblock's LittleEndian to FALSE (also when creating the header!) and
read the type code and payload length. I store the payload len.
Next, I check if the expected payload len is non-zero. Then I check if
the socket has that much data available yet. If not, I return. If the
data is there, I read only that amount from the socket that the
payload length designates.
After processing this block, I loop back to checking for another header.
That's a pretty safe and extensible algo, I think.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|