This document provides source code in Visual Basic 6.0 for creating a simple chatting application using Windows sockets. The code includes two forms - Form 1 which runs the server and Form 2 which runs the client. Form 1 displays the local IP, listens for connections on port 5050, and handles receiving and sending data. Form 2 prompts the user for the server IP, connects to the server on port 5050, and also handles receiving and sending data. The code enables two users to connect and chat in a simple client-server chatting application.
This document provides source code in Visual Basic 6.0 for creating a simple chatting application using Windows sockets. The code includes two forms - Form 1 which runs the server and Form 2 which runs the client. Form 1 displays the local IP, listens for connections on port 5050, and handles receiving and sending data. Form 2 prompts the user for the server IP, connects to the server on port 5050, and also handles receiving and sending data. The code enables two users to connect and chat in a simple client-server chatting application.
Me.Text1.Text = Winsock1.LocalIP End Sub Private Sub Form_Load() Winsock1.LocalPort = 5050 Winsock1.Listen Form2.Show End Sub Private Sub Text]_KeyPress(KeyAscii As integer) If KeyAscii = 13 Then Winsock1.SendData Text] End If End Sub Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long) If Winsock1.State <> sckClosed Then Winsock1.Close Winsock1.Accept requestID MsgBox "Client Terkoneksi", vbInformation End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim data As String Winsock1.GetData data Me.Text2.Text = data End Sub
Form 2
private Sub Form_Load()
Dim ip As String ip = InputBox("Masukan IP Server") Winsock1.Connect ip, 5050 End Sub Private Sub Text2.KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then winsock1.SendData Text 2 End If End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim data As String Winsock1.GetData data Me.Text1.Text = data End Sub