Greetings and salutations Gurus

I am trying (in vain) to write a routine that will continuously attempt to reconnect my client program to the server when it disconnects. Could be because the server program is not running, crashed or whatever. Here's what I've got so far:

Code:
  ' Attempt connection to server
  Do Until Winsock1.State = sckConnected
    If Winsock1.State = sckError Or sckConnecting Then
      Winsock1.Close
      DoEvents
    End If
    
    If Winsock1.State = sckClosed Then
      Winsock1.Connect sSvrName, 4500
      DoEvents
    End If
  Loop
This works if I put a breakpoint at the connect statement, and allow it the time to connect. I dont think the connect command has enough time to actually connect before it reaches the 'If Winsock1.State=SckError Or sckConnecting Then' line.

Any suggestions would be received gratefully, thanks.