Results 1 to 12 of 12

Thread: Winsock problem

  1. #1

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    Hello,
    I have a problem. I have an array of winsock control on my form, the problem is that, the Winsock1_SendComplete event doesnt fire up, and neither does, Winsock1_Connect. Can anyone tell me why"?

  2. #2
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    Post

    Im great with winsock, but I need to see the
    code.Zip it all up and then upload it in a reply.
    ill take a look at it.

  3. #3
    Member
    Join Date
    Mar 2000
    Location
    Galt, Ca
    Posts
    47
    did you close winsock in the first place?

    winsock1.close

    then all your code

  4. #4

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    Here it is, I hope you can solve the problem,
    Attached Files Attached Files

  5. #5
    Addicted Member
    Join Date
    Feb 2001
    Posts
    140

    Possible problem

    You need to make sure that you declare the subs right.

    Winsock1_SendComplete(Index As Integer)
    That makes it possible to keep track of which winsock number you are using.
    -Nean

  6. #6

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    I got the event trigger going, but there is another problem. I am using TCP for my winsock. When I try to send a lot of information using a loop, the client doesnt seem to receive it well. It adds garbage to it, or all the data sent to the client is received like on big line.

    Code:
    Public Function SendDirListing(Path as string)
    dim I as integer
    dir1.path = path
    for I = 0 to dir1.listcount - 1
        winsock1.senddata dir1.list(I)
    next I
    end function

  7. #7
    Guest
    This is a common problem. When you use SendDatas close together like in a loop, the data from the first SendData might not have been physically sent out of the computer when the next SendData is invoked. Thus you'll end up with missing strings, truncated strings or no string at all. To get around this make use of the SendComplete event.

    Code:
    Dim SendComplete As Boolean
    
    Private Sub Form_Load()
        SendComplete = False
    End Sub
    
    Public Function SendDirListing(Path as string)
        Dim I As Integer
        Dir1.Path = Path
        For I = 0 to Dir1.ListCount - 1
            SendComplete = False
            Winsock1.SendData Dir1.List(I)
            Call WaitComplete
        Next I
    End Function
    
    Private Sub WaitComplete()
        Do Until SendComplete = True
            DoEvents
        Loop
    End Sub
    
    Private Sub Winsock1_SendComplete()
        SendComplete =True
    End Sun
    Because unlike most things in VB, SendData actually takes time to do. This above code will make sure on SendData is complete before moving on.

  8. #8

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    Still the same problem, ):

  9. #9
    Guest
    The above is usually the only cause of the problem. Perhaps you can post your code and it can be looked at.

  10. #10

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    I already posted the code in a zip file above.

  11. #11
    Guest
    Your code

    Code:
    Public Sub SendMsg(Msg As String, Index As Integer)
    On Error Resume Next
    If Sending = True Then
        Do While Not Sending = False
            DoEvents
        Loop
    End If
    frmMain.sckMain(Index).SendData DataEncode(Msg)
    Do While Not Sending = False
        DoEvents
    Loop
    End Sub
    Here, you are see if Sending is False, if not then it won't continue. Yet nowhere in your code was Sending ever set to True in the first place, so your 'wait until finished' loop basically has no effect.

  12. #12

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    Code:
    Public Sub SendMsg(Msg As String, Index As Integer)
    On Error Resume Next
    If Sending = True Then
        Do While Not Sending = False
            DoEvents
        Loop
    End If
    frmMain.sckMain(Index).SendData DataEncode(Msg)
    Sending = True
    Do While Not Sending = False
        DoEvents
    Loop
    End Sub
    
    Private Sub sckMain_SendComplete(Index as Integer)
           Sending = False
    end sub
    Still no effect, ):

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