|
-
Aug 4th, 2000, 05:32 AM
#1
Thread Starter
New Member
I am using a winsock and I am passing data back in forth from one app to another.
My problem is this: I have one app sending data to another app via winsock and I want the app sending data to wait until it gets back acknowledgement from the other app that it recieved the data and is ready for another record so basically what am trying to do is wait until the "DataArrival" event has been triggered then move on to the next record.
-
Aug 4th, 2000, 08:07 AM
#2
Hyperactive Member
What you need is to have a while statement like this
Code:
confirmData = False
'send data
while confirmData
DoEvents
wend
DoEvents will let events be fired off still in the loop, so DataArrival will be able to be fired.
Code:
'in data arrival you will need
confirmData = true
[Edited by billrogers on 08-04-2000 at 09:10 AM]
-
Aug 14th, 2000, 05:53 AM
#3
Lively Member
-
Aug 14th, 2000, 06:15 AM
#4
New Member
or, to do it the easy (i didn't say 'the best') way, you could use my ActiveX control, which put's the next VB line to be processed on a hold for a specified number of miliseconds.
e.g.
Form1.Winsock1.SendData "hi guys" 'send 1st record
Form1.KDelay.Delay 1 'wait one millisecond
Form1.Winsock1.SendData "I guess 1 milisecond should provide the connection with enough time to fullfill transmission." 'send 2nd record
Download this ActiveX at my homepage:
http://home.wxs.nl/~sunfield/kevin/personal/
The OCX can be found under the "ActiveX Section".
The file you then want to download is called 'Delay'.
Hope I could be of any assistance,
Kevin
-
Aug 14th, 2000, 12:24 PM
#5
Lively Member
-
Aug 14th, 2000, 01:14 PM
#6
New Member
You are correct, that's why told told you it is not the BEST way. My OCX can indeed never guarantee a transmission success. However, i've written too many winsock applications, also for businness-use, and I always find that the delay works perfectly wel. It's also easy to use, and does not require any additional network traffic, nor Server+Client Side programming.
For more stablility, you can always upgrade the milliseconds-attribute. I would never go higher than 5, however.
btw
excuse my english.
-
Aug 15th, 2000, 01:33 AM
#7
Lively Member
-
Aug 15th, 2000, 01:43 AM
#8
PowerPoster
Originally posted by Kevin_van_Zonneveld
You are correct, that's why told told you it is not the BEST way. My OCX can indeed never guarantee a transmission success. However, i've written too many winsock applications, also for businness-use, and I always find that the delay works perfectly wel. It's also easy to use, and does not require any additional network traffic, nor Server+Client Side programming.
For more stablility, you can always upgrade the milliseconds-attribute. I would never go higher than 5, however.
btw
excuse my english.
I don't think the your OCX is needed, because the delay in 1 miliseconds can be archieve easily by calling the GetTickCount Win32 API function like below:
Code:
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private t1 As Long, t2 As Long
Public Sub Delay(ByVal Interval)
t1 = GetTickCount
t2 = 0
While t2 - t1 < Interval
DoEvents
t2 = GetTickCount
Wend
End Sub
Yet, what rekcus said is the best way to implement the data transfer between to application through Winsock control. Each application must send the "ACK" or "NAK" after the DataArrival Events is fire. This is to ensure a better data transfer.
Code:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
'//Process the received data
'Do What ever your data validation over here.
'It is not recommended to perform the data
'validation over here. You should call another
'Sub routine to do it.
'Send back the Acknowledgement to the sender
'Over here I use the Chr(2) and Chr(3) is because it is
'the standard protocol being widly use in data communication.
'If the validation is pass then send the ACK
Winsock1.Sendata Chr(2) 'For ACK
'If the validation fail then just send the NAK
Winsock1.Sendata Chr(3) 'For NAK
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|