Results 1 to 2 of 2

Thread: Winsock-problem ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Posts
    2

    Wink

    On this moment I am trying to construct a client/server chat.
    (Part of) The following code resides on the server:

    If strCommand$ = "[JOIN]" Then
    Call sckConnect(Index).SendData("[OPERATOR] " & txtNick.Text)

    DoEvents
    For lngIndex& = 1 To sckConnect().Count - 1
    If sckConnect(lngIndex&).State = sckConnected Then
    Call sckConnect(lngIndex&).SendData("[USERLIST] " & strBuf1$)
    endif
    DoEvents
    Next lngIndex&

    For lngIndex& = 1 To sckConnect().Count - 1
    If sckConnect(lngIndex&).State = sckConnected Then
    Call sckConnect(lngIndex&).SendData("[SYSMSG] " & "*** " & strArgument$ & " has joined the chat.")

    End If
    DoEvents
    Next lngIndex&

    End If

    On the client-site I receive:
    [OPERATOR] and so on and that is OK.

    Than I receive on the client-site:
    [USERLIST]XXXXX[SYSMSG]XXXXXXX

    So the second "senddata" bind the two strings (which should be send separately) to one ????

    Can someone help me ??
    Ger

  2. #2
    Guest
    When you use 2 SendDatas closely together and they are sending large amounts of data, the first SendData might not have completed sending when the second SendData is called. Winsock gets around this by sticking the two strings together, so you might end up with truncated strings, multiple strings or no strings at all. To solve this make use of the SendComplete event:

    Code:
    Dim Complete As Boolean
    
    Private Sub YourSub()
    
    If strCommand$ = "[JOIN]" Then 
        Complete = False
        sckConnect(Index).SendData("[OPERATOR] " & txtNick.Text)
        Call WaitComplete
        'DoEvents  No need for this
    
        For lngIndex& = 1 To sckConnect().Count - 1 
            If sckConnect(lngIndex&).State = sckConnected Then 
                Complete = False
                sckConnect(lngIndex&).SendData("[USERLIST] " & strBuf1$) 
                Call WaitComplete
            End If
            'DoEvents  No need for this
        Next lngIndex& 
    
        For lngIndex& = 1 To sckConnect().Count - 1 
            If sckConnect(lngIndex&).State = sckConnected Then 
                Complete = False
                sckConnect(lngIndex&).SendData("[SYSMSG] " & "*** " & strArgument$ & " has joined the chat.") 
                Call WaitComplete
            End If 
            'DoEvents No need for this
        Next lngIndex& 
    
    End If 
    End Sub
    
    Private Sub sckConnect_SendComplete(Index As Integer)
        Complete = True
    End Sub
    
    Private Sub WaitComplete()
        Do Until Complete = True
            DoEvents
        Loop
    End Sub
    The added code will make sure that a SendData completes sending before the code moves on. You seem to have the idea that DoEvents gives time for Winsock to send, but it really doesn't

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