January 28, 2021
Hot Topics:

Communicating over a Network

  • By Sam Huggill
  • Send Email »
  • More Articles »

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:

While Winsock1.State

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

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

This article was originally published on November 20, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date