Soyez le premier à donner votre avis sur cette source.
Vue 5 680 fois - Téléchargée 646 fois
'Pour plus de renseignements : Sirotilc@ifrance.com ' 'Si vous utilisez mon code, précisez la source, merci ! Dim Port As Integer Dim PortOK As Boolean Dim NbJoueurs As Integer Private Sub Form_Load() NbJoueurs = 0 PortOK = False End Sub Private Sub Form_Unload(Cancel As Integer) Dim I As Integer For I = 0 To (NbJoueurs) Winsock1(I).Close Next I Winsock2.Close End Sub Private Sub Creer_Click() If Winsock1(0).State <> sckConnected And Creer.Caption = "Créer Partie" Then Creer.Caption = "Déconnecter" Rej.Enabled = False Winsock3.LocalPort = "3000" Winsock3.Listen Port = 2000 Winsock1(0).LocalPort = Str(Port) Winsock1(0).Listen Else Creer.Caption = "Créer Partie" Rej.Enabled = True Dim I As Integer For I = 0 To (NbJoueurs) Winsock1(I).Close Next I End If End Sub Private Sub Rej_Click() If Winsock2.State <> sckConnected Then If Rej.Caption = "Rejoindre" Then Creer.Enabled = False Rej.Caption = "Déconnecter" If Winsock2.State <> sckConnected Then Port = 3000 Winsock2.RemoteHost = "180.100.81.57" Winsock2.RemotePort = Str(Port) Winsock2.Connect End If Else Winsock2.Close Creer.Enabled = True Rej.Caption = "Rejoindre" End If End If Exit Sub End Sub Private Sub Quitter_Click() Dim I As Integer For I = 0 To (NbJoueurs) Winsock1(I).Close Next I Winsock2.Close End End Sub Private Sub Timer1_Timer() If PortOK = True Then PortOK = False Winsock3.Close Winsock3.Listen End If End Sub Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long) If Winsock1(Index).State <> sckClosed Then Winsock1(Index).Close Winsock1(Index).Accept requestID Port = Port + 1 Load Winsock1(Index + 1) Winsock1(Index + 1).LocalPort = Str(Port) Winsock1(Index + 1).Listen NbJoueurs = Index + 1 End Sub Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long) Dim s As String Winsock1(Index).GetData s, vbString Winsock1(Index).SendData "Tu es Joueur " & (Index + 1) & "." End Sub Private Sub Winsock2_ConnectionRequest(ByVal requestID As Long) If Winsock2.State <> sckClosed Then Winsock2.Close Winsock2.Accept requestID End Sub Private Sub Winsock2_Connect() Winsock2.SendData "Client OK" End Sub Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long) Dim s As String Winsock2.GetData s, vbString Select Case Mid(s, 1, 6) Case "[Port]" Port = Val(Mid(s, 7, Len(s))) Winsock2.Close Winsock2.RemotePort = Str(Port) Winsock2.Connect Case Else MsgBox s End Select End Sub Private Sub Winsock3_ConnectionRequest(ByVal requestID As Long) If Winsock3.State <> sckClosed Then Winsock3.Close Winsock3.Accept requestID Winsock3.SendData "[Port]" & Str(Port) PortOK = True End Sub
A+
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.