How do you tell when Winsock's DataArrival Event is done? 
Author Message
 How do you tell when Winsock's DataArrival Event is done?

I noticed that winsock control has a sendprogress event and a
sendcomplete event for sending data. However, when receving data there
is only a DataArrival event so you can read in all incoming data. Is
there ANY way of telling when the data being received has completed? I
noticed there is a BytesReceived function which tells how many bytes
currently recide in the input queue. Some of you may say just see if
this value equates to 0 and if it is then the data is complete;
however there are times when this function returns back 0 before it is
done and then 10 secs later it has a value > 0. I need something that
will absolutely tell me when the data received is completely done. Is
there a extremely reliable way?

Please reply via email



Sun, 13 May 2001 03:00:00 GMT  
 How do you tell when Winsock's DataArrival Event is done?

Quote:
>I noticed that winsock control has a sendprogress event and a
>sendcomplete event for sending data. However, when receving data there
>is only a DataArrival event so you can read in all incoming data. Is
>there ANY way of telling when the data being received has completed? I
>noticed there is a BytesReceived function which tells how many bytes
>currently recide in the input queue. Some of you may say just see if
>this value equates to 0 and if it is then the data is complete;
>however there are times when this function returns back 0 before it is
>done and then 10 secs later it has a value > 0. I need something that
>will absolutely tell me when the data received is completely done. Is
>there a extremely reliable way?

No, and there can not be.  When you use SendData the winsock control knows
how many bytes you just gave it.  That makes it possible for it to tell you
when it has passed them all to the network.

The TCP/IP protocol is permitted to break up or combine the SendData packets
you create as needed depending on network activity/capacity/etc.  When you
send 1 chunk of data the recipient may see many smaller chunks arrive.  When
you send mutliple chunks the recipient may see only 1.

The only way for the receiver to know that everything has been received is
if you have defined your own protocol for telling it that.  For example, if
you are sending lines of text you can end each line with vbNullChar or
vbCRLF or anything else thaat can not appear inside the "real" data.  The
recipient then knows that when that character, or characters, is found
anywhere in the arriving data the transmission is complete.

Another method is to prefix each send with the size:
    Winsock1.SendData Chr$(Len(sData)) & sData
(if the length can be >255 you have to use 2 or more leading bytes)
The receiver takes in the first byte (or two or...) and converts that back
to a number and then waits to receive that many bytes.

Note that either way the receiving end must buffer all incoming data and
pull it apart.  Using the first method, for example, say you do this:
   Winsock1.SendData "ABC" & vbNullChar
   Winsock1.SendData "DEF" & vbNullChar
The recipient must be prepared for any arrival combination:
maybe one chunk:  "ABC<0>DEF<0>"
maybe two: "ABC<0>" and "DEF<0>"
maybe something off the wall: "AB" and "C<0>DEF" and "<0>"
The only guarantee (assuming TCP protocol) is that the data will arrive in
order.  If you use UDP protocol you have no guarantee of the arrival order,
or even if it wil arrive at all.



Sun, 13 May 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How do you tell when Winsock's DataArrival Event is done?

2. How do you tell when Winsock's DataArrival Event is done?

3. How do you tell when Winsock's DataArrival Event is done?

4. How do you tell when Winsock's DataArrival Event is done?

5. How do you tell when Winsock's DataArrival Event is done?

6. Please tell me what I am doing wrong - DAO parameter Append Query :(

7. Will somebody tell me what I am doing wrong with this ListView Control

8. tell another program i am done

9. ADO thinks DBMS is done, but DBMS ain't done

10. How to tell when all a form and all it's elements are done loading

11. Determining when a file's done with Winsock

12. MCI control doesn't generate DONE Event

 

 
Powered by phpBB® Forum Software