Results 1 to 8 of 8

Thread: Winsock Concatenation problem...

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Location
    PA
    Posts
    7

    Exclamation 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]

  2. #2
    Guest
    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

  3. #3
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    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 !!!!!

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Location
    PA
    Posts
    7

    Arrow 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.

  5. #5
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    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 !!!!!

  6. #6
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Smile

    I agree with Sunnyl suggestion, If you your program is running in a LAN envirnment, then you can forget about the SendComplete events. But once your chat program is running through the Internet, then I'm sure you need to make use of the [SendComplete[/b] event to ensure the data is being send to the respective cleint. This was due to the delay in the Internet connection. This is one of the main factor you need to concern.

    This because recently, I did wrote a file transfer program with server (QServer.EXE) and client (MConnecXion.exe). What my program do is the Client can post the filename through a ASP page then the ASP page will pass this filename to my QServer with my own COM object. Then only QServer transfer the file to all the connected clients.

    When I test it in a LAN envirnment, it working fine. But once my colleague run the client on the other place, she always get Time Out error and casue the file fail to transfer.

    Beside the SendComplete events, your client my be able to acknowledge the server about the message is complete received, before the server continue send the message to the next client.

    Hope I'm correct.

  7. #7
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    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 !!!!!

  8. #8

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Location
    PA
    Posts
    7

    Smile

    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
  •  



Click Here to Expand Forum to Full Width