|  
    
 Avoir la connaissance de la façon de créer un salon de discussion en utilisant Microsoft Visual Basic Express peut vous faire gagner du temps lorsque vous avez besoin pour créer une application de chat room . Visual Basic Express est disponible gratuitement à toute personne intéressée dans la création d' applications à l'aide de VB.NET . Un salon de discussion implique deux applications , le serveur et le client . Le serveur gère toutes les connexions clientes , ainsi que l'application cliente se connecte aux utilisateurs de la salle des serveurs pour envoyer des messages . Instructions   1  Démarrez Microsoft Visual Basic Express, puis cliquez sur "Nouveau projet ". Dans le volet gauche de votre écran, sélectionnez " Application console. " Cliquez sur « OK ».   2   Appuyez sur "Ctrl " + "A", puis appuyez sur «Supprimer». Copiez et collez le code suivant dans votre " Module1.vb " pour créer le programme du serveur : Photos   importations System.Net.Sockets     Imports System.Text     Module Module1     clientsList As New Hashtable     Sub Main ( )     serverSocket As New TcpListener ( 8888)     clientSocket As TcpClient     infiniteCounter As Integer     contre As Integer     serverSocket.Start ()     msg ( " serveur de conversation de route .... " ) contre     = 0     infiniteCounter = 0     infiniteCounter = 1 To 2     infiniteCounter = 1   compteur de   + = 1     clientSocket = serverSocket.AcceptTcpClient ()     Dim bytesFrom ( 10024 ) As Byte     dataFromClient Dim As String     NetworkStream As NetworkStream = _     clientSocket.GetStream ( )     networkStream.Read ( bytesFrom , 0, CInt ( clientSocket.ReceiveBufferSize ) )     dataFromClient = System.Text.Encoding.ASCII.GetString ( bytesFrom )     dataFromClient = _     dataFromClient.Substring (0, dataFromClient.IndexOf ("$" ) )     clientsList ( dataFromClient ) = clientSocket     diffusion ( dataFromClient + " Inscrit " , dataFromClient , faux)     msg ( dataFromClient + " Inscrit le chat room " )     client As New handleClinet     client.startClient ( clientSocket , dataFromClient , Sous     Sous msg ( mesg ByVal As String )     mesg.Trim ()     Console.WriteLine ( ">>" + mesg )     End Sub     diffusion Private Sub (msg ByVal As String , _     uName ByVal As String , drapeau ByVal As Boolean )     Dim Item Comme DictionaryEntry     Pour chaque élément de clientsList     broadcastSocket As TcpClient     broadcastSocket = C ( Item.Value , TcpClient )     broadcastStream As NetworkStream = _     broadcastSocket.GetStream ()     broadcastBytes As [ Byte ] ()     Si flag = true Ensuite     broadcastBytes = Encoding.ASCII.GetBytes ( uName + " dit: " + msg)     Else     broadcastBytes = Encoding.ASCII.GetBytes (MSG)     End If     broadcastStream.Write ( broadcastBytes , 0, broadcastBytes . longueur )     broadcastStream.Flush ()     Suivant     End Sub     public Class handleClinet     clientSocket As TcpClient     Dim ClNO As String     clientsList As Hashtable     public Sub startClient ( ByVal inClientSocket Comme TcpClient , _ ByVal     clineNo As String , ByVal cLIST Comme Hashtable )     Me.clientSocket = inClientSocket     Me.clNo = clineNo     Me.clientsList = cLIST     ctThread As Threading.Thread = New Threading.Thread ( AddressOf doChat )     ctThread.Start ()     End Sub     doChat Private Sub ()     infiniteCounter As Integer Dim     RequestCount As Integer     Dim bytesFrom ( 10024 ) As Byte     dataFromClient As cordes     sendBytes As [ Byte ] ()     serverResponse Dim As String Photos   RCount Dim As String     RequestCount = 0     infiniteCounter = 1 To 2     infiniteCounter = 1     essayer et   RequestCount = RequestCount + 1     NetworkStream As NetworkStream = _     clientSocket.GetStream ()     networkStream.Read ( bytesFrom , 0, CInt ( clientSocket.ReceiveBufferSize ) )     dataFromClient = System.Text.Encoding.ASCII.GetString ( bytesFrom )     dataFromClient = _     dataFromClient.Substring (0, dataFromClient.IndexOf ("$" ) )     msg ( " De client - " + ClNO + ":" + dataFromClient )     RCount = Convert.ToString ( RequestCount )     diffusion ( dataFromClient , ClNO , vrai)     Catch ex As Exception     MsgBox ( ex.ToString )     Fin essayer et   Suivant     End Sub     End Class of   End Module   3   Démarrez Microsoft Visual Basic express, puis cliquez sur "Nouveau projet ". Dans le volet gauche de votre écran, sélectionnez " application Windows Forms . "Cliquez sur " OK ". Cliquez sur le" volet " , puis double -cliquez sur" Toolbox TextBox "pour ajouter une nouvelle zone de texte . Ajoutez deux zones de texte. Ajoutez deux boutons dans le menu" Outils " . < br > Hôtels 4   Double- cliquez sur le formulaire , puis appuyez sur "Ctrl" + " A. " Press Copiez et collez le code suivant dans le module " Form1.vb " pour créer le programme client «Supprimer». : Photos   importations System.Net.Sockets     Imports System.Text     public Class Form1     clientSocket As New System.Net.Sockets.TcpClient () Photos   Serverstream As NetworkStream     readData Dim As String     infiniteCounter As Integer     Private Sub Button1_Click ( expéditeur de ByVal comme System.Object , _ < br >   ByVal e As System.EventArgs ) Poignées Button1.Click     outStream As Byte () = _     System.Text.Encoding.ASCII.GetBytes ( TextBox2.Text + " $ ")     serverStream.Write ( outStream , 0, outStream.Length )     serverStream.Flush ()     End Sub     msg Private Sub ( )     Si Me.InvokeRequired Puis     Me.Invoke (New MethodInvoker ( AddressOf msg) )     Else     TextBox1.Text = TextBox1.Text + Environment.NewLine + ">>" + readData     End If End Sub         Private Sub Button2_Click ( expéditeur de ByVal comme System.Object , _   < p> ByVal e As System.EventArgs ) Handles Button2.Click     readData = " Les liens entre l' serveur de chat ... "   msg ( )     clientSocket.Connect ( " 127.0.0.1 " , 8888) Label1.Text =     ' « Programme de socket client - serveur connecté ... "    Serverstream = clientSocket.GetStream ()     outStream Dim As Byte () = _     System.Text.Encoding.ASCII.GetBytes ( TextBox3.Text + "$")     serverStream.Write ( outStream , 0, outStream.Length ) < br >   serverStream.Flush ()     ctThread As Threading.Thread = New Threading.Thread ( AddressOf getMessage )     ctThread.Start ()     End Sub     Private Sub getMessage ()     infiniteCounter = 1 To 2     infiniteCounter = 1     Serverstream = clientSocket.GetStream ()     buffSize As Integer     réservé Dim ( 10024 ) As Byte     buffSize = clientSocket.ReceiveBufferSize     serverStream.Read ( cours d'eau , 0, buffSize )     returndata As String = _     System.Text.Encoding.ASCII.GetString ( cours d'eau )     readData = "" + returndata     msg ( )     Suivant     End Sub End Class       5   exécutez le programme serveur abord en appuyant sur la touche "F5 " , puis exécutez le programme client . Tapez votre nom dans " Textbox3 " et cliquez sur " Button2 " pour se connecter au serveur. Tapez un message dans " TextBox2 », puis cliquez sur " Button1" pour envoyer un message .    
 
 |