Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winsock DataArrival Event 1

Status
Not open for further replies.

HouDog

Programmer
Aug 14, 2003
54
0
0
CA
Hi All, I am having a little problem with winsock and I hope someone can help me out.

I am using UDP Protocol and want to simulate a SEND/Ack mechanism.

I have a form with a button on it. When I click the button, I attempt to send my data. The receiving end returns an "Ack".

Also, I have implemented a Timeout feature and a Max Retry feature whereby if the Ack is not received within the Timeout, I re-send up to the number of Retry count allowed.

Here is some code...in a nutshell

Private Sub c_Socket_DataArrival(ByVal bytesTotal As Long)
Dim bytes() As Byte
Socket.GetData bytes
boolAckReceived = True
End Sub

Private Sub ButtonClick()
Dim SendTime as long
Dim TestInterval as long
dim TimeDiff as long

SendTime = SendData(b, RetryCount)
Do While Not boolAckReceived And RetryCount < 4
TestInterval = Timer() * 1000 'msecs
TimeDiff = TestInterval - SendTime
If TimeDiff >= 250 Then
RetryCount = RetryCount + 1
SendTime = SendData(b, RetryCount)
End If
Loop
End Sub

Private Function SendData() As Long
Socket.SendData ("my data")
SendData = Timer() * 1000
End Function

Everything works great in most cases...except when it falls into the retry loop.

What happens is that all the "re-sends" are sent and then all the "ack" are received. It seems that the DataArrival event does not get fired until ALL the retry have been sent. ie the While loop is complete.

I can put in a DoEvents in the code but then the button frees and I am able to click again. It is important to maintain the completion of the retries until an ack is received.

How do I get the DataArrival event to trigger or register during the loop ????????

Thanks.


 
I would recommend disabling the button, including the DoEvents while waiting for the response, and enabling the button once response is recieved or failure established.
-Max
 
Thank you for your response. However, the problem is that the DataArrival event does not fire during the loop. Once the iterations of the loop have completed, then I get all my ack at once. For example, if the loop iterates 3 times, i get 3 ack in a row once the loop has finished. For some reason, the processing of the loop prevents the DataArrival event from firing.

 
shakespeare5677's point is that including DoEvents in the retry loop will fix the DataArrival event issue (as you also found, according to your original post). The further detail they provide is a workaround for the button problem that ensues
 
Hmm...looks like I won't be able to get away from DoEvents. Is there an equivalent to DoEvents that will allow me to process just non-UI events ?

Just curious.

Thanks for your answers.
 
Not a built-in one, no. But a keyword search in this forum should find one or two posts from myself and others that provide an alternative. You want to be looking for MsgWaitForMultipleObjects with QS_ALLINPUT (or a more limited QS_ of your choice) followed by a selective PeekMessage/TranslateMessage/DispatchMessage sequence (essentially your own DoEvents, but one that you can control).
 
OK cool. I'll take a look. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top