|
-
Nov 18th, 2000, 12:24 PM
#1
Thread Starter
New Member
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]
-
Nov 18th, 2000, 04:24 PM
#2
I'm not sure if I understood your code right, but the problem of strings being stuck together when sending can be solved by putting the following Send methods into the preceeding Winsock's SendComplete event.
Sunny
-
Nov 18th, 2000, 06:52 PM
#3
Hyperactive Member
I don't quite understand why you are sending data in the send complete event ? Would you care to elaborate on this ?
The folling has worked for me . This is in my server application . It's not the best , but it works . It has some overhead because it sends to all the socket instances and errors out on the disconnected ones . Well at least it did until I added a line of your code ,Hope you got something out of this .
[]P
[Code]
Public Function SendStrng(ToSend As String)
'this sends to all winsocks 1 to MaxWinsock
Dim Counter As Integer
On Error GoTo Errhandler ' Error handling enabled
For Counter = 1 To MaxWinsock
If Winsock1(Counter).State = 7 Then Winsock1(Counter).SendData ToSend
Next
Errhandler:
Resume Next
On Error GoTo 0 ' Error handling disabled
End Function
[Code]
Visual Basic 6 SP4 on win98se
QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!
-
Nov 18th, 2000, 07:21 PM
#4
Thread Starter
New Member
Re:
I'm sorry if my comments confused you, the comment was for the timer, not the SendComplete event. I originally had it as simple as yours, where I just did all Sends with one function. This works with only one connection, but with multiple connections, when sending to multiple people close in code, sometimes one of the Sends doesn't even at all go through. So what I did, is whenever I wanted to send something I would add it to a collection. Concurrently, there is a timer that is constantly checking whether there was anything in the collection, and sending it if there was. This got rid of the problem of certain Sends not going through, but now sometimes the sends would concatenate to each other. So what I did is in the timer I would set isSending to true, and when the Send was complete (i.e. the SendComplete event), it would set the variable to false, so that when the timer is going through the next time it can send the next thing in the collection. I'm not sure if you tested with multiple computers or multiple connections to your server, with multiple Sends close to each other in code... but your function won't work. Hopefully that clears it up a little.
-
Nov 18th, 2000, 07:39 PM
#5
Hyperactive Member
It seems to work fine for me . If I have any problems I'll let you know .
[]P
Visual Basic 6 SP4 on win98se
QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!
-
Nov 18th, 2000, 11:06 PM
#6
-
Nov 18th, 2000, 11:09 PM
#7
Hyperactive Member
I have only run it on a lan . I may have future issues to deal with . Thanks for the information .
[]P
Visual Basic 6 SP4 on win98se
QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!
-
Nov 19th, 2000, 09:51 AM
#8
Thread Starter
New Member
Actually I got it working. What I did is on the Client application, I would send a command back that would tell the Server that that specific client has received the last message, and only then will it send any concurrent messages. This seems to work fine for me right now, but I'm sure I'll be back with problems some time in the future. Thanks everyone for all your help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|