P
Paul M. Seabury
I have read the MSDN docs, many examples, and even coded some async
client/servers. My question is this. How do you know when the data you are
expecting has arrived? I understand that when EndReceive() returns 0, there
is no more data to read. But what if there is really more data coming, it
just hasn't arrived yet? A small example.
Suppose I want to write a basic XML server. The server reads and writes XML
documents to transfer data. Suppose I have the usual Asnyc setup with a
1024Byte receive buffer, and a state object with a string (or stringbuilder)
member that keeps track of all the data thus received from a particular
socket. How do I know that I've gotten an entire XML doc? What if the doc
is a few MB big and a call to EndReceive returns 0 because the sender has
stalled? Maybe I get half the doc, then sender stalls, my Async callback
returns 0 on endreceive because there is no more data at that instant. Is
that how it works? Do I need to try and validate the doc (in my state
object) every time my callback returns to see if the entire doc has arrived?
This just degrades to polling if that is the case. Any enlightenment would
be greatly appreciated. Sorry about all the questions, but I cannot (thus
far) understand how you know when all of the data the client intends to send
has arrived. Obviously if the client closes the socket I will know, but
what if he/she keeps the tcp stream open and periodically sends XML docs my
way?
Thanks in advance,
Paul Seabury
Elantech Inc.
(e-mail address removed)
client/servers. My question is this. How do you know when the data you are
expecting has arrived? I understand that when EndReceive() returns 0, there
is no more data to read. But what if there is really more data coming, it
just hasn't arrived yet? A small example.
Suppose I want to write a basic XML server. The server reads and writes XML
documents to transfer data. Suppose I have the usual Asnyc setup with a
1024Byte receive buffer, and a state object with a string (or stringbuilder)
member that keeps track of all the data thus received from a particular
socket. How do I know that I've gotten an entire XML doc? What if the doc
is a few MB big and a call to EndReceive returns 0 because the sender has
stalled? Maybe I get half the doc, then sender stalls, my Async callback
returns 0 on endreceive because there is no more data at that instant. Is
that how it works? Do I need to try and validate the doc (in my state
object) every time my callback returns to see if the entire doc has arrived?
This just degrades to polling if that is the case. Any enlightenment would
be greatly appreciated. Sorry about all the questions, but I cannot (thus
far) understand how you know when all of the data the client intends to send
has arrived. Obviously if the client closes the socket I will know, but
what if he/she keeps the tcp stream open and periodically sends XML docs my
way?
Thanks in advance,
Paul Seabury
Elantech Inc.
(e-mail address removed)