|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
PETIT EXEMPLE DE CHAT AVEC WINSOCK
Information sur la source
Description
Bon comme le dit le titre, voici un petit exemple d'un chat entre client et serveur via winsock. Soyez indulgent, c'est l'un de mes premier code! n_n' Ben le code est banal, on choisis son pseudo et on envoie son texte. On peut aussi choisir le port de connexion depuis le serveur. Voila voila ... A+
Source
- 'Côté client
-
- Private Sub Command1_Click()
- If Command1.Caption = "Se &connecter" Then
- Winsock.Close
- Winsock.Connect Text1.Text, Text2.Text
- End If
- If Command1.Caption = "Se &déconnecter" Then
- Winsock.Close
- Winsock.Listen
- Command1.Caption = "Se &connecter"
- Label3.Caption = "Déconnecté"
- Form1.Height = 2150
- End If
- End Sub
-
- Private Sub Command2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Winsock.SendData "pseudo" & Text3.Text
- RTB.Text = RTB.Text + Text3.Text + " : " + Text4.Text + vbCrLf + "------------------------------------------------------------------------------------" + vbCrLf
- End Sub
-
-
- Private Sub Winsock_Close()
- Winsock.Close
- Winsock.Listen
- Command1.Caption = "Se &connecter"
- Label3.Caption = "Déconnecté"
- Form1.Height = 2150
- End Sub
- Private Sub Winsock_Connect()
- Winsock.SendData "Connecté"
- Label3.Caption = "Connecté"
- Command1.Caption = "Se &déconnecter"
- Form1.Height = 13000
- End Sub
- Private Sub Winsock_ConnectionRequest(ByVal requestID As Long)
- Winsock.Close
- Winsock.Accept requestID
- End Sub
- Private Sub Form_Load()
- Form1.Height = 2150
- End Sub
-
- Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
- Dim data As String
- Winsock.GetData data
- If Left(data, 2) = "ok" Then
- Winsock.SendData "texte" & Text4.Text
- Text4.Text = ""
- End If
-
-
- If Left(data, 6) = "pseudo" Then
- RTB.Text = RTB.Text + Right(data, Len(data) - 6) + " : "
- Winsock.SendData "ok"
- End If
- If Left(data, 5) = "texte" Then
- RTB.Text = RTB.Text + Right(data, Len(data) - 5) + vbCrLf + "------------------------------------------------------------------------------------" + vbCrLf
- End If
- End Sub
-
-
- 'Côté serveur
-
- Private Sub Command2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Winsock.SendData "pseudo" & Text1.Text
- RTB.Text = RTB.Text + Text1.Text + " : " + Text2.Text + vbCrLf + "------------------------------------------------------------------------------------" + vbCrLf
- End Sub
-
- Private Sub port_change_Click()
- Port = InputBox("Indiquer le nouveau port de connection (9999 par défaut) :", "Changement de port", "9999")
- Winsock.Close
- Winsock.LocalPort = Val(Port)
- Winsock.Listen
- End Sub
-
-
- Private Sub Winsock_ConnectionRequest(ByVal requestID As Long)
- Winsock.Close
- Winsock.Accept requestID
- End Sub
- Private Sub Form_Load()
- Form1.Height = 690
- Form1.Width = 6945
- Winsock.Close
- Winsock.Listen
- End Sub
- Private Sub Winsock_Close()
- Winsock.Close
- Winsock.Listen
- etat.Caption = "Etat : Déconnecté"
- Form1.Height = 690
- Form1.Width = 6945
- End Sub
- Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
- Dim data As String
- Winsock.GetData data
- If Left(data, 8) = "Connecté" Then
- etat.Caption = "Etat : Connecté"
- Form1.Height = 11580
- Form1.Width = 6945
- End If
-
- If Left(data, 2) = "ok" Then
- Winsock.SendData "texte" & Text2.Text
- Text2.Text = ""
- End If
-
-
- If Left(data, 6) = "pseudo" Then
- RTB.Text = RTB.Text + Right(data, Len(data) - 6) + " : "
- Winsock.SendData "ok"
- End If
- If Left(data, 5) = "texte" Then
- RTB.Text = RTB.Text + Right(data, Len(data) - 5) + vbCrLf + "------------------------------------------------------------------------------------" + vbCrLf
- End If
- End Sub
'Côté client
Private Sub Command1_Click()
If Command1.Caption = "Se &connecter" Then
Winsock.Close
Winsock.Connect Text1.Text, Text2.Text
End If
If Command1.Caption = "Se &déconnecter" Then
Winsock.Close
Winsock.Listen
Command1.Caption = "Se &connecter"
Label3.Caption = "Déconnecté"
Form1.Height = 2150
End If
End Sub
Private Sub Command2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Winsock.SendData "pseudo" & Text3.Text
RTB.Text = RTB.Text + Text3.Text + " : " + Text4.Text + vbCrLf + "------------------------------------------------------------------------------------" + vbCrLf
End Sub
Private Sub Winsock_Close()
Winsock.Close
Winsock.Listen
Command1.Caption = "Se &connecter"
Label3.Caption = "Déconnecté"
Form1.Height = 2150
End Sub
Private Sub Winsock_Connect()
Winsock.SendData "Connecté"
Label3.Caption = "Connecté"
Command1.Caption = "Se &déconnecter"
Form1.Height = 13000
End Sub
Private Sub Winsock_ConnectionRequest(ByVal requestID As Long)
Winsock.Close
Winsock.Accept requestID
End Sub
Private Sub Form_Load()
Form1.Height = 2150
End Sub
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim data As String
Winsock.GetData data
If Left(data, 2) = "ok" Then
Winsock.SendData "texte" & Text4.Text
Text4.Text = ""
End If
If Left(data, 6) = "pseudo" Then
RTB.Text = RTB.Text + Right(data, Len(data) - 6) + " : "
Winsock.SendData "ok"
End If
If Left(data, 5) = "texte" Then
RTB.Text = RTB.Text + Right(data, Len(data) - 5) + vbCrLf + "------------------------------------------------------------------------------------" + vbCrLf
End If
End Sub
'Côté serveur
Private Sub Command2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Winsock.SendData "pseudo" & Text1.Text
RTB.Text = RTB.Text + Text1.Text + " : " + Text2.Text + vbCrLf + "------------------------------------------------------------------------------------" + vbCrLf
End Sub
Private Sub port_change_Click()
Port = InputBox("Indiquer le nouveau port de connection (9999 par défaut) :", "Changement de port", "9999")
Winsock.Close
Winsock.LocalPort = Val(Port)
Winsock.Listen
End Sub
Private Sub Winsock_ConnectionRequest(ByVal requestID As Long)
Winsock.Close
Winsock.Accept requestID
End Sub
Private Sub Form_Load()
Form1.Height = 690
Form1.Width = 6945
Winsock.Close
Winsock.Listen
End Sub
Private Sub Winsock_Close()
Winsock.Close
Winsock.Listen
etat.Caption = "Etat : Déconnecté"
Form1.Height = 690
Form1.Width = 6945
End Sub
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim data As String
Winsock.GetData data
If Left(data, 8) = "Connecté" Then
etat.Caption = "Etat : Connecté"
Form1.Height = 11580
Form1.Width = 6945
End If
If Left(data, 2) = "ok" Then
Winsock.SendData "texte" & Text2.Text
Text2.Text = ""
End If
If Left(data, 6) = "pseudo" Then
RTB.Text = RTB.Text + Right(data, Len(data) - 6) + " : "
Winsock.SendData "ok"
End If
If Left(data, 5) = "texte" Then
RTB.Text = RTB.Text + Right(data, Len(data) - 5) + vbCrLf + "------------------------------------------------------------------------------------" + vbCrLf
End If
End Sub
Fichier Zip
Sources du même auteur
Sources de la même categorie
Sources en rapport avec celle ci
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Client et serveur IRC avec Winsock (Aide !!!) [ par KOOK ]
Salut, j'ai télécharger plusieurs sources de client et serveur irc mais aucune ne marche, j'ai un problème avec Winsock, pourriez vous m'aider, existe
TRES IMPORTANT !! [ par Lead ]
Avis aux utilisateur de winsock.Voila mon probleme :- Application client/serveur Démarrage : Server en écoute et client se connecte au server.Fermetur
création d'un client =) [ par Whitewolf ]
Salut à tous ! =))Est ce que quelqu'un saurait comment une application client -> server doit aller chercher les informations sur le server. Je m'ex
Winsock client qui ne marche qu'une fois! [ par Olivier ]
Mon application client serveur fonctionne parfaitement une seule fois.La seconde fois, le client plante sur .connect en annonçant "adresse en cours d'
winsock client/serveur [ par Meddah ]
je veux réalisé une application qui calcule les tarifs dans un cybercafé je cherche soi un exemple pour base sur lui soi une aide sur winsock car je n
winsock client/serveur [ par Meddah ]
je veux réalisé une application qui calcule les tarifs dans un cybercafé je cherche soi un exemple pour base sur lui soi une aide sur winsock car je n
winsock : [ par Yan ]
Voila je code une app client/serveurJe cherche à faire un serveur multi-clientsbon chez mio je lance le machin la connexion s'établit, cool :)Je quitt
help me : winsock prob... [ par Hardousss ]
Salut tlm !!chui un debutant en vb et c'est ma premiere participation au fameux forum vbfrance.com donc...i trust in ur ingenuity guys to help me sol
Peut-on avoir plusieurs connections sur un winsock? [ par crendel ]
Je suis en train de faire un logiciel qui marche sur le principeclient/server. J'aimerai mettre plusieurs client connecté au meme server. C'est possib
Prob avec un projet Winsock help plz [ par YnOThAr ]
Lut all !!! Donc voila, je ne suis encore qu'un débutant en Visual Basic, mais comme apparementc'est un "langage" simple et comme je fais deja un peu
|
Téléchargements
Logiciels à télécharger sur le même thème :
Comparez les prix Nouvelle version
|