PDA

Click to See Complete Forum and Search --> : Winsock-problem ?


Ger
Feb 2nd, 2001, 02:31 PM
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 ??

Feb 2nd, 2001, 05:16 PM
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:


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