Communicating over a Network
The last thing you will discover in this article are operation time outs. When using the Winsock control, or in fact any Internet comms control, you need to be able to detect a time out. This occurs, for instance, when an application you are talking to stops responding while you are communicating with it. If you didn't watch for a time out, then you program would just sit around waiting for the other program to respond. The easiest way to watch for these is by using a timer control.
By setting the Interval property to a reasonable length, for instance 30000, then you can detect time outs. Again, use events to tell the user what's going on. You need to do this in the timers Timer event:
Private Sub Timer1_Timer() RaiseEvent TimeOut End Sub
To finish, here are some quick guidelines for specifying addresses:
- Where possible use an IP address (127.0.0.1) instead of computer names because the Winsock control has to resolve a host name to an IP address - this takes some time.
- If you connect to the net over a dial up connection, you can still get this to work. When you have logged on, use the Winsock's LocalIP method to return to current IP address. This way you can send it to your friend and he/she can connect to you.
Page 7 of 7