Results 1 to 5 of 5

Thread: sendcomplete yet not firing!!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2008
    Posts
    327

    sendcomplete yet not firing!!

    this is the only way i can think of using sendcomplete to send data via winsock.my programming language is vb 6 . here is my code
    vb Code:
    1. public SendComplete as boolean
    2.  
    3. Public Sub WaitForWinsock()
    4.    
    5. While Not SendComplete
    6.      
    7.          DoEvents
    8.  
    9.     Wend
    10. End Sub
    11.  
    12. Private Sub sock1_SendComplete()
    13.  
    14.  SendComplete = True
    15.  
    16. End Sub
    17.  
    18. private sub CmdSend_click()'an example of how i send data
    19.  dim strData as string
    20.  strData = "Hello"
    21.  
    22. sendComplete = False
    23.  
    24. winsock.senddata strData
    25.  
    26. WaitForWinsock
    27.  
    28. End Sub
    is there anybetter way to code ..? coz my data are not being send properly

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: sendcomplete yet not firing!!

    Why not just use the SendComplete event to begin with?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2008
    Posts
    327

    Re: sendcomplete yet not firing!!

    Quote Originally Posted by Atheist
    Why not just use the SendComplete event to begin with?
    a small example to get me started would be highly appreciated , and it would be helpful to others aswell

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: sendcomplete yet not firing!!

    The SendComplete event doesn't really mean the previous send completed, it means that you can do another SendData without it blocking. In other words it means there is room to buffer more outgoing data.

    Effectively though this is the same thing. Thus you can generally treat it as meaning the previous send completed... and thus the name.


    It is my opinion that using DoEvents() calls in a Form with a Winsock control leads to programs that just don't always work. You never need DoEvents() with Winsock unless you are doing something wrong.

    In the most general case you would use some data structure as a queue of outgoing messages. Each SendComplete event you would take the next queued message and send it. To queue a new message add it to the queue structure and check for some "sending" Boolean. This variable would be set False in your SendComplete handler and True after any SendData. If when you queue a new message "sending" is False, SendData with your new message and set sending=True.

    The SendComplete handler would go something like:
    Code:
    sending = False
    If Queue is not Empty Then
        msg = Queue.Remove() 'Remove 1st msg from Queue
        wsk.SendData msg
        sending = True
    End If
    The QueueMsg routine would go like:
    Code:
    If not sending Then
        wsk.SendData msg
        sending = True
    Else
        Queue.Insert msg
    End If
    For Queue you could use something as simple as a Collection.


    Now most programs don't require this generality. Instead of an explicit queue they use some other global indicators of state to decide what to do in the SendComplete handler.

    If sending a file in chunks, the SendComplete might check for the file number variable <> 0 and if so read another chunk from disk and then call SendData with it. Upon EOF it might close the file and set the file number variable to 0.

    Sending array elements or anything else can be handled in a similar manner.


    Writing a bunch of straight-line code to send stuff is where people go wrong. You can't send over Winsock synchronously because it is not an instantaneous process. If you did your program would hang.

    This is where using a queue can help. Instead of "send, send, send" you can just "queue, queue, queue" and let the SendComplete process parcel things out over the Winsock control.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2008
    Posts
    327

    Re: sendcomplete yet not firing!!

    while we are at this post ,i would like to ask one more thing. when i am just using winsock.senddata it works fine but when i am using it under if and else statement the data does not get sent immediately instead it fires only after i receive a message or send another data . why is it so ? and how can i overcome it ?

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