1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
Imports System.Net.Sockets
Imports System.IO
Public Class ChatNgX
Private EcouteAll As NetworkStream
Private EcouteEcrit As StreamWriter
Private Ecoutelist As StreamReader
Private Client As New TcpClient
Private EtatLecture As New Threading.Thread(AddressOf Listen)
Private Delegate Sub DAddItem(ByVal s As String)
Private Pseudo As String
Dim Evenement As Boolean = False
Dim AdresseIP As String
Dim ConfirmIP As Boolean = False
Dim ConfirmPseudo As Boolean = False
Dim MsgBoxIP
Dim MsgBoxPseudo
Private Sub AddItem(ByVal s As String)
ListChat.Items.Add(s)
ListChat.SelectedIndex = ListChat.Items.Count - 1
ListChat.ClearSelected()
End Sub
Private Sub ChatNgX_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
BtnEnvoyer.Enabled = False
If (Evenement = True) Then
Try
Client.Connect(AdresseIP, 8000)
If Client.Connected Then
EcouteAll = Client.GetStream
EcouteEcrit = New StreamWriter(EcouteAll)
Ecoutelist = New StreamReader(EcouteAll)
EcouteEcrit.WriteLine(Pseudo)
EcouteEcrit.Flush()
EtatLecture.Start()
Else
MsgBox("Le serveur n'est pas lancé !", MsgBoxStyle.Exclamation, "Aucun Serveur trouvé")
Application.Exit()
End If
Catch ex As Exception
MsgBox("Le serveur n'est pas lancé !", MsgBoxStyle.Exclamation, "Aucun Serveur trouvé")
Application.Exit()
End Try
End If
End Sub
Private Sub Listen()
If (Evenement = True) Then
While Client.Connected
Try
Me.Invoke(New DAddItem(AddressOf AddItem), Ecoutelist.ReadLine)
Catch
MsgBox("Le serveur n'est pas lancé !", MsgBoxStyle.Exclamation, "Aucun Serveur trouvé")
Application.Exit()
End Try
End While
End If
End Sub
Private Sub BtnEnvoyer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnvoyer.Click
EcouteEcrit.WriteLine(Txtchat.Text)
EcouteEcrit.Flush()
Txtchat.Clear()
End Sub
Private Sub ChatNgX(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.FormClosed
End
Application.Exit()
End Sub
Private Sub ChatNgX_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
While ConfirmIP = False
AdresseIP = InputBox("Adresse du Serveur : ", "Connexion au Serveur")
If (AdresseIP = "") Then
MsgBoxIP = MsgBox("Vous n'avez pas entré d'Adresse IP !", MsgBoxStyle.RetryCancel, "Aucune Adresse IP")
Evenement = False
Else
Evenement = True
ConfirmIP = True
End If
If (MsgBoxIP = MsgBoxResult.Cancel) Then
Application.Exit()
End If
End While
While ConfirmPseudo = False
Pseudo = InputBox("Entrer votre Pseudo : ", "Choisir un pseudo")
If (Pseudo = "") Then
MsgBoxPseudo = MsgBox("Vous n'avez pas entré de Pseudo !", MsgBoxStyle.Information, "Aucun Pseudo")
Evenement = False
Else
Evenement = True
ConfirmPseudo = True
End If
If (MsgBoxPseudo = MsgBoxResult.Cancel) Then
Application.Exit()
End If
End While
End Sub
Private Sub BtnQuitter_Click(sender As Object, e As EventArgs) Handles BtnQuitter.Click
End
End Sub
Private Sub BtnCouleur_Click(sender As Object, e As EventArgs) Handles BtnCouleur.Click
ColorDialog1.ShowDialog()
Txtchat.ForeColor = ColorDialog1.Color
End Sub
Private Sub Txtchat_TextChanged(sender As Object, e As EventArgs) Handles Txtchat.TextChanged
If (Txtchat.Text <> "") Then
BtnEnvoyer.Enabled = True
Else
BtnEnvoyer.Enabled = False
End If
End Sub
End Class |
Partager