PDA

Click to See Complete Forum and Search --> : Winsock Problem


Gekitotsu
Jan 3rd, 2001, 05:07 PM
When using the Winsock Control in VB6.. I have this problem..

If I use a socket array.. Say Socket(1) socket(2) etc.. and I try to use something like a for next loop to send to all the connections..

Example:
For Q = 1 to 5
Socket(Q).SendData "Whatever" & Vblf
next

It doesn't send to any but the last one (Socket(5)) .. However if after I do that .. And try sending something else to the single socket.. Lets say 3..
Socket(3).SendData "Stuff" & VbLf
Then It sends "Whatever" & Vblf & "Stuff" & VbLf

I need it to send when its "Supposed" to... Not wait till it is called seperatly..

Is there some kind of character.. Or command to make each send..

Any help would be appreciated.

Jan 3rd, 2001, 11:20 PM
When you have mutliple SendData's in close together, like in a For Next loop the chances are the next SendData is excuted before the one before it finished sending, Winsock takes care of this by sticking the two together regardless and this gets you your missing results or weird strings. To solve this make use of the SendComplete event.


Dim Complete As Boolean

Private Sub Form_Load()
Complete = False
End Sub

Private Sub MySub()
Dim i As Integer

For i = 0 To 4
Complete = False
Winsock(i).SendData YourString
Do Until Complete = True
DoEvents
Loop
Next i
End Sub

Private Sub Winsock_SendComplete(Index As Integer)
Complete = True
End Sub


This makes sure that the send finishes before the loop moves on.

Sunny

Gekitotsu
Jan 4th, 2001, 09:50 PM
Thank you so much!

That has been bugging me for like the past 3 weeks. >.<

Hehe, I can't believe I didn't think of that, Anyway.. Thanks again. :)