08. maj 2006 - 21:58Der er
1 kommentar og 1 løsning
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
Du kan gøre det sådan her... så slipper du også for et par variabler
Private Sub Command1_Click() populateMessage txtMsg.Text End Sub
Private Sub Form_Load() ReDim users(0) ReDim SendData(0) ReDim recievedData(0)
winsock(0).LocalPort = 5000 winsock(0).Listen End Sub
Private Sub WinSock_ConnectionRequest(Index As Integer, ByVal requestID As Long) If Index = 0 Then Load winsock(winsock.Count) winsock(winsock.ubound).LocalPort = 0 winsock(winsock.ubound).Accept requestID End If End Sub
Private Sub WinSock_DataArrival(Index As Integer, ByVal bytesTotal As Long) winsock(Index).GetData tekst, vbString Debug.Print "Control no. " & Index & ": " & tekst End Sub
Private Sub populateMessage(txt As String) For x = 1 To winsock.ubound If (winsock(x).State = 7) Then winsock(x).SendData txt & vbCrLf DoEvents End If Next x End Sub
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.