Dim i As Integer = objClient.Count - 1
ma liste : 0, 1, 2
Private Sub AttenteConnexion() While 1 If objClient.Count < ConnMax.Value Then objClient.Add(objServer.AcceptTcpClient()) ThConn.Add(New Threading.Thread(AddressOf GestionConnexion)) If VerifieClient(objClient.Count - 1) <> 0 Then ThConn(ThConn.Count - 1).Start() Else objClient(objClient.Count - 1).Close() objClient.Remove(objClient(objClient.Count - 1)) End If ' Sinon, on suppérieur au nombre de connexion MAX on met le thread en pause. Else Threading.Thread.Sleep(100) End If End While End Sub
Private Sub GestionConnexion() Dim i As Integer = objClient.Count - 1
' ----------------------------------------------------------------------- ' Déconnexion d'un participant ' ----------------------------------------------------------------------- Private Sub Deconnexion(ByVal i As Integer) accepter(i) = False objClient(i).Close() objClient.Remove(objClient(i)) Pseudo.Remove(Pseudo(i)) accepter.Remove(i) 'Envoi de la déconnexion du participant à tous le monde. For a As Integer = 0 To objClient.Count - 1 If Pseudo(a) <> "" And a <> i And accepter(i) = True Then Dim StreamW As NetworkStream = objClient(a).GetStream Dim envoi = Encoding.UTF8.GetBytes("- " + Pseudo(i) + " a quitté la conversation." + vbCrLf) Try StreamW.Write(envoi, 0, envoi.Length) Catch End Try End If Next a End Sub
Pseudo.Remove(Pseudo(i))
accepter.Remove(i)
Envoi de la déconnexion du participant à tous le monde.
For a As Integer = 0 To objClient.Count - 1
if Pseudo(a) <> "" And a <> i And accepter(i) = True Then
Dim StreamW As NetworkStream = objClient(a).GetStream
Dim envoi = Encoding.UTF8.GetBytes("- " + Pseudo(i)
+ " a quitté la conversation." + vbCrLf)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub Deconnexion(ByVal i As Integer) 'Envoi de la déconnexion du participant à tous le monde. For a As Integer = 0 To objClient.Count - 1 If Pseudo(a) <> "" And a <> i And accepter(i) = True Then Dim StreamW As NetworkStream = objClient(a).GetStream Dim envoi = Encoding.UTF8.GetBytes("- " + Pseudo(i) + " a quitté la conversation." + vbCrLf) Try StreamW.Write(envoi, 0, envoi.Length) Catch End Try End If Next a accepter(i) = False objClient(i).Close() objClient.Remove(objClient(i)) Pseudo.Remove(Pseudo(i)) accepter.Remove(i) End Sub
J'ai donc (pour tester) mis la boucle For en bas