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 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.