Private Sub cmdConnect_Click()
'Sub for the connect button
sckClient.Close 'Close the socket
sckClient.Connect "127.0.0.1", 8989 'Make a connection to 127.0.0.1 on port 8989
'The 127.0.0.1 IP will loop back to your own computer
'You could replace this with a server IP
End Sub
Private Sub cmdSend_Click()
'Send button sub
sckClient.SendData txtSend.Text
End Sub
Private Sub sckClient_Close()
'This event is fired when the remote side ends the connection
lblStatus.Caption = "Connection closed"
End Sub
Private Sub sckClient_Connect()
'This event is fired when the connection attempt has been made and established
lblStatus.Caption = "Connected"
sckClient.SendData "HELLO" 'Send some data to the server saying HELLO
End Sub
Private Sub sckClient_DataArrival(ByVal bytesTotal As Long)
'When some data is received on the socket, this event is fired
Dim strData As String
sckClient.GetData strData, vbString 'Grab the data received and store it in strData variable
MsgBox "Data Arrived From Server: " & strData 'Display the data received in a message box
End Sub
Private Sub sckClient_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
'This event is fired when there is an error in the socket
'this event is used more in the client socket when making connections
'we will just put a message box which will display the error
MsgBox "Error: " & Number & ", " & Description, vbCritical, "Client Error"
End Sub