Professional Documents
Culture Documents
Aim:To develop a visual basic program to perform an Chat Server Using Socket Control. Algorithm:Server:Step1: Winsocket is placed in the client and the server. Step2: Winsocket just connect client and server machine using accept request method. Step3: Here the local port number is specified and port wait for the response from client. Step4: Here send data method is used to send data to the specified port and getdata from the client. Client:Step1: The name of the Remote Host should be specified. Step2: By checking connet,the connection is established b/w server and the client. Step3: Send Data and GetData recive and send chat message using winsocket object.
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long) If Winsock1.State <> sckClosed Then Winsock1.Close Winsock1.Accept requestID End If End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Winsock1.GetData X Text1.Text = "" Text2.Text = X End Sub Client Side:Dim X As String Private Sub CmdClear_Click() Text1.Text = "" Text2.Text = "" End Sub Private Sub CmdConnect_Click() Winsock1.RemoteHost = "192.168.1.10" Winsock1.Connect Server.Show End Sub Private Sub CmdExit_Click() End End Sub Private Sub CmdSend_Click() If Winsock1.State = sckConnected Then Winsock1.SendData Text1.Text Server.Show
Else MsgBox "Server Is Not Connected...First Connect To Server.", vbApplicationModal, "" End If End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Winsock1.GetData X Text1.Text = "" Text2.Text = X End Sub
OutPut:Server Output:-
Client Output:-
Result:-