Winsock Concatenation Problem...
Hello,
I have made a chat program for multiple users to access. I have made a Server program, and a User program. I am using an array of Winsock Connections to connect with multiple people, so that people can chat with each other. My problem is that if I have two send commands that are close to each other in code in my Server program, even though they are supposed to send sperately, upon sending, one concatenates to the other, so the received data is not what I want it to be. I tried to circumvent this problem by having a boolean variable (isSending) which I set to true before every seperate send, and set to false in my Winsock_SendComplete() event. Please tell me what I'm doing wrong, or how to fix it. Below are snipets of my code that relate to this problem (Also, I have downloaded the Service pack 4 which supposedly fixes some type of Winsock problem... I'm not sure if it's this one or not, but if it is, it's not working):
Code:
Dim mSendList As New Collection 'General Declarations
Dim isSending As Boolean
'This is the function I call throughout my program when I
'want to send something. What it does is add the string to
'the mSendList collection, and the tmrSendData Timer
'iterates through this collection every millisecond, and
'sends whatever data is in the collection.
Private Sub sckSend(sckIndex As Integer, str As String)
mSendList.Add sckIndex & "[PARSE]" & str
End Sub
Private Sub Form_Load()
isSending = False
End Sub
Private Sub sckConnection_SendComplete(Index As Integer)
isSending = False
End Sub
'This function goes through the mSendList collection
'and sends whatever is in it depending on whether
'isSending is true or false.
Private Sub tmrSendData_Timer()
On Error Resume Next
Dim sendToIndex%
Dim msg1
Do
If mSendList.Count = 0 Then Exit Do
If isSending Then Exit Do
sendToIndex = Val(mSendList(1))
msg1 = Mid(mSendList(1), InStr(1, mSendList(1), "[PARSE]") + 7)
If sckConnection(sendToIndex).State = 7 Then
sckConnection(sendToIndex).SendData msg1
Text1.Text = Text1.Text & "To " & GetUser(sendToIndex) & ": " & msg1 & vbCrLf
Text1.SelStart = Len(Text1.Text)
isSending = True
While isSending
DoEvents
Wend
End If
mSendList.Remove 1
Loop
End Sub
Thank you ahead of time.
[Edited by eydelber on 11-18-2000 at 12:30 PM]