SendData to multiple clients - HELP!!!!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: SendData to multiple clients - HELP!!!!

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    SendData to multiple clients - HELP!!!!

    [Originally posted by Raymond Williams]

    I'm having some problems with some code I've written. The server is accepting and handling connections fine. I have a parser function to handle incoming data, that looks at the first word (everything up to the first space) and runs it through a case statement to determine if it is a command (like /msg or /me in IRC clients) and if it is not, then it simply resends the whole thing to all clients attached.

    For commands that send data to only one client, there seem to be no problems. However, when the server sends data to all clients, it only shows up in the last client. However, if I then send a message to one of the other clients alone, it flushes any messages that it should have gotten so far plus the current message to the client! This has me very confused, it's almost like it's buffering it somewhere then flushing the whole thing down. Any help anyone could provide would be greatly appreciated. Email me if you need more code or anything. Thanks!

    Raymond

    Sub ProcessCommand(Index As Integer, sData As String)
    ˙ ˙ Dim sCommand As String
    ˙ ˙ Dim sParams As String
    ˙ ˙ Dim CurChar As Integer
    ˙ ˙ Dim i As Integer
    ˙ ˙
    ˙ ˙ sCommand = ""
    ˙ ˙ sParams = ""
    ˙ ˙
    ˙ ˙ For CurChar = 1 To Len(sData) Step 1
    ˙ ˙ ˙ ˙ If Mid(sData, CurChar, 1) <> &quot; &quot; Then
    ˙ ˙ ˙ ˙ ˙ ˙ sCommand = sCommand + Mid(sData, CurChar, 1)
    ˙ ˙ ˙ ˙ Else
    ˙ ˙ ˙ ˙ ˙ ˙ sParams = Mid(sData, CurChar + 1)
    ˙ ˙ ˙ ˙ ˙ ˙ Exit For
    ˙ ˙ ˙ ˙ End If
    ˙ ˙ Next CurChar
    ˙ ˙
    ˙ ˙ Select Case LCase(sCommand)
    ˙ ˙ ˙ ˙ Case &quot;/googly&quot;
    ˙ ˙ ˙ ˙ ˙ ˙ sckMain(Index).SendData &quot;Great googly moogly&quot;
    ˙ ˙ ˙ ˙ Case Else
    ˙ ˙ ˙ ˙ ˙ ˙ For i = 1 To intMax
    ˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙ If sckMain(i).State = 7 Then
    ˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙ sckMain(i).SendData sData
    ˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙ End If
    ˙ ˙ ˙ ˙ ˙ ˙ Next i
    ˙ ˙ End Select
    End Sub

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:SendData to multiple clients - HELP!!!!

    [Originally posted by FreeVBCode.com]

    What is the variable intMax equal to. Also, have you stepped through this code to ensure that data is being sent through to each instance of winsock?

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:SendData to multiple clients - HELP!!!!

    [Originally posted by Raymond Williams]

    intMax is always set to the highest index value of Winsock controls that have been loaded. There is the default winsock control on the server form with index 0. Every time it recieves a connection request, it increments intMax, does a Load sckMain(intMax) and assigns the new connection to that winsock control.

    I haven't stepped through, but I know the data is being sent to each instance, because as soon as I do the /googly from one of the other clients, what it gets is everything that should have gone to it but hasn't yet, strung together, with the Great Googly Moogly line appended to that. I guess I'll step through it all the same, I don't know why I didn't do that yet really.

    Thanks,

    Raymond

  4. #4
    Join Date
    Aug 2004
    Posts
    43,023

    Re:SendData to multiple clients - HELP!!!!

    [Originally posted by Bj”rn Gustafsson]

    Uhm, have you tried adding DoEvents in the sending loop?

    For i = 1 To intMax
    ˙ If sckMain(i).State = 7 Then
    ˙ ˙ sckMain(i).SendData sData
    ˙ End If
    ˙ DoEvents
    Next i

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center