Communicating over a Network
Connecting to a computer is not as easy as just calling the Connect method and specifying a remote IP and port. You need to do a fair amount of 'handshaking', which is making sure that the other computer is still there and wanting to connect.
First, before starting a connection, it's always good practice to close any current operations before you start to ensure that the Winsock control is available:
Winsock1.Close While Winsock1.State DoEvents Wend
See the use of the While Wend loop? That is to make sure that you don't start trying to do something while the winsock control is still finishing an operation.
When connecting, you will also need to check for errors:
If Err Then Msgbox Err.Number, Err.Description Err = 0 End If
As done before, you need to make sure that you don't start doing tasks before the control is ready:
While Winsock1.Waiting DoEvents Wend
Most of the code you have seen now forms the bulk of a Connect method. You will now learn about the Listen method. The Listen method is what the receiving computer must do to hear Connect methods.
Page 4 of 7