Hello,
I have a problem. I have an array of winsock control on my form, the problem is that, the Winsock1_SendComplete event doesnt fire up, and neither does, Winsock1_Connect. Can anyone tell me why"?
I got the event trigger going, but there is another problem. I am using TCP for my winsock. When I try to send a lot of information using a loop, the client doesnt seem to receive it well. It adds garbage to it, or all the data sent to the client is received like on big line.
Code:
Public Function SendDirListing(Path as string)
dim I as integer
dir1.path = path
for I = 0 to dir1.listcount - 1
winsock1.senddata dir1.list(I)
next I
end function
This is a common problem. When you use SendDatas close together like in a loop, the data from the first SendData might not have been physically sent out of the computer when the next SendData is invoked. Thus you'll end up with missing strings, truncated strings or no string at all. To get around this make use of the SendComplete event.
Code:
Dim SendComplete As Boolean
Private Sub Form_Load()
SendComplete = False
End Sub
Public Function SendDirListing(Path as string)
Dim I As Integer
Dir1.Path = Path
For I = 0 to Dir1.ListCount - 1
SendComplete = False
Winsock1.SendData Dir1.List(I)
Call WaitComplete
Next I
End Function
Private Sub WaitComplete()
Do Until SendComplete = True
DoEvents
Loop
End Sub
Private Sub Winsock1_SendComplete()
SendComplete =True
End Sun
Because unlike most things in VB, SendData actually takes time to do. This above code will make sure on SendData is complete before moving on.
Public Sub SendMsg(Msg As String, Index As Integer)
On Error Resume Next
If Sending = True Then
Do While Not Sending = False
DoEvents
Loop
End If
frmMain.sckMain(Index).SendData DataEncode(Msg)
Do While Not Sending = False
DoEvents
Loop
End Sub
Here, you are see if Sending is False, if not then it won't continue. Yet nowhere in your code was Sending ever set to True in the first place, so your 'wait until finished' loop basically has no effect.
Public Sub SendMsg(Msg As String, Index As Integer)
On Error Resume Next
If Sending = True Then
Do While Not Sending = False
DoEvents
Loop
End If
frmMain.sckMain(Index).SendData DataEncode(Msg)
Sending = True
Do While Not Sending = False
DoEvents
Loop
End Sub
Private Sub sckMain_SendComplete(Index as Integer)
Sending = False
end sub