Results 1 to 8 of 8

Thread: winsock waiting issue

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Posts
    5

    Question

    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.

  2. #2
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    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]

  3. #3
    Lively Member rekcus's Avatar
    Join Date
    Jan 1999
    Location
    Kuala Lumpur
    Posts
    122

    Thumbs up

    Try to have some kind of communicatin protocol between the two. The receiving end should then reply with an "ACK" when it has successfully received the transmission.

    Have the data_arrival event of the winsock at the sending side process the "ACK" message. When "ACK" is detected, send the next record.

    Cheers,
    penyou!

    "The code bytes.."

  4. #4
    New Member
    Join Date
    Aug 2000
    Posts
    4

    Lightbulb

    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

  5. #5
    Lively Member rekcus's Avatar
    Join Date
    Jan 1999
    Location
    Kuala Lumpur
    Posts
    122

    Thumbs up

    I am afraid that does not fully ascertain the successful receipt of the first set of data sent.

    Cheers,
    penyou!

    "The code bytes.."

  6. #6
    New Member
    Join Date
    Aug 2000
    Posts
    4
    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.

  7. #7
    Lively Member rekcus's Avatar
    Join Date
    Jan 1999
    Location
    Kuala Lumpur
    Posts
    122

    Wink

    Well, a delay of 5 milliseconds should be alright for a single client settting.
    You should consider either the communication protocol or increasing the delay for networks with higher traffic / higher number of terminals.

    Still it will depend on the importance of the data being transfered.

    penyou!

    "The code bytes.."

  8. #8
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    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
  •  



Click Here to Expand Forum to Full Width