Results 1 to 8 of 8

Thread: sending data to multiple winsock connections

  1. #1
    Guest
    Help! i am trying to send data to multiple users using the winsock control. the program i am creating is a chat program that has a server that clients connect to. the code i am currently using is below.

    Dim i As Integer

    For i = 1 To intMax
    SendKeys "{ENTER}", False
    MsgBox ""
    sckServer(i).SendData data
    Next

    intMax is an integer that keeps track of the number of winsock controls.
    when i dont use the sendkeys and msgbox, the data doesnt get sent back to the first client to connect to the server. when i put the sendkeys and msgbox in, it works fine. i cant understand why this is, any ideas would be appreciated! Thanks.

  2. #2
    New Member
    Join Date
    Apr 2000
    Posts
    2

    Winsock "queue" bug!

    This is a bug in VB 5 and 6... It queues up data to any previously opened connection, instead of sending the data, like it should.

    Check out msdn.microsoft.com for more information..

    If anyone knows a way around this, PLEASE respond! I really am not looking forward to rewriting my server in the winsock API...

    Thanks..

  3. #3
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    I had also this problem, try the following...
    Wait for the WinSock.SendComplete -event before you go on with the loop. Looks something like this:
    Code:
    'Declarations
    Global Sent as Boolean
    
    'In sckServer_SendComplete
    Sent = True
    
    'Your Loop
    Dim A As Integer 
    
    For A = 1 To intMax
       'Send data
       sckServer(A).SendData data
    
       'Wait for sent-event
       Sent = False
       While Sent = False
          DoEvents
       Wend
    Next
    Ok then, hope this helps ya...

  4. #4
    New Member
    Join Date
    Apr 2000
    Posts
    2

    That code is a no go.. :(

    That code only "waits" for the data to send. This works on one connection, but there is a bug with an array of connections that makes the previously connected connectiosn NOT get their data (it queues instead of sends it)... It will send the data, if it recieves some data from that client, so constantly pinging the server "works", but is obviously very inefficient.. All that code will do is wait indefinately until it can send it (which it won't be able to do because of that bug..

    Thanks anyway..

  5. #5
    Lively Member
    Join Date
    Nov 1999
    Location
    Melbourne, Victoria, Australia
    Posts
    126
    Tested code...

    Dim i As Integer

    For i = 1 To intMax
    SendKeys "{ENTER}", False
    MsgBox ""
    sckServer(i).SendData data
    DoEvents 'Flush buffer/sockets and what not
    Next
    Regards,

    Paul Rivoli
    ---------------------
    [email protected]
    http://members.dingoblue.net.au/~privoli

  6. #6
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    I think it's a really stupid way to do this with a msgbox!

    Erm, njaguar, did you try out my code?

  7. #7
    Lively Member
    Join Date
    Nov 1999
    Location
    Melbourne, Victoria, Australia
    Posts
    126
    Dim i As Integer

    For i = 1 To sckServer.UBound
    if sckServer.State = SckConnected Then sckServer(i).SendData data
    Next
    Regards,

    Paul Rivoli
    ---------------------
    [email protected]
    http://members.dingoblue.net.au/~privoli

  8. #8
    New Member
    Join Date
    Nov 1999
    Posts
    15

    Socket Wrench vs. Winsock

    This problem only occurs with the Winsock control. My friend had a problem very much like this, and he simply switched to the Catalyst Socket Wrench control. It has a lot more features than Winsock (slightly more complex too.) You can download the control for free at http://www.catalyst.com/
    Catalyst makes controls for just about every protocol, so make sure you get the right one (TCP/IP.) It is a great control and I have never once gone back to using the Winsock control since I have used Socket Wrench.

    ~Stoinker~

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