Multi winsock connection melder fejl
Hejsa, har en fejl her..Når der kommer 1 brugere ind + mig, så virker det fint, men hvis der er 3 inde, så melder den fejl.
Den melder fejl ved:
If (WinSock(x).State = 7) Then
og siger:
Control array element '5' doesn't exist
i denne kode:
Private Instances As Long
Private Sub Form_Load()
Instances = 0
WinSock(0).LocalPort = 9999
WinSock(0).Listen
End Sub
Private Sub WinSock_Close(Index As Integer)
Unload WinSock(Index)
End Sub
Private Sub WinSock_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
Instances = Instances + 1
Load WinSock(Instances)
WinSock(Instances).LocalPort = 0
WinSock(Instances).Accept requestID
End If
End Sub
Private Sub WinSock_DataArrival(Index As Integer, ByVal bytesTotal As Long)
WinSock(Index).GetData tekst, vbString
For x = 1 To Instances
If (WinSock(x).State = 7) Then
WinSock(x).SendData tekst
For y = 1 To 10000
DoEvents
Next y
End If
Next x
Debug.Print "Control no. " & Index & ": " & tekst '(overvåg trafik)
End Sub
