im making the client connect to the port on the ip (as the server is already listening on the same port for incoming connections)

VB Code:
  1. Private Sub cmdConnect_Click()
  2.         WStcpClient.Close
  3.         WStcpClient.RemoteHost = txtServerIp.Text
  4.         WStcpClient.RemotePort = 15000
  5.         WStcpClient.Connect
  6. End Sub

but sometimes it doesnt work on the first click of the button, i usually need to close the form, click the button again and then it connects, can someone give me any error checking code so i can print something like

'Unable to connect to server, please try again'