Using Internet Transfer Control Methods

The Internet Transfer control has five methods and one event, as listed in Table 11.3.

Table 11.3: Internet Transfer Control Methods and Event

Method/Event Description
Cancel method Terminates a currently outstanding request and closes the connection to the remote server
Execute method Executes the specified command
GetChunk method Retrieves a buffer full of data from the remote server
GetHeader method Retrieves header information from a file on the remote server
OpenURL method Retrieves information from the remote server
StateChanged event Occurs each time the control’s state changes

Interacting with the Server

There are two main ways to interact with the server. The first is to use the OpenURL method, and the second is to use the Execute method with the GetChunk and GetHeader methods as needed.

The OpenURL method retrieves the document specified by the URL as either a String or Byte Array. If you are transferring binary information, you should use a Byte Array to hold the results; otherwise, the information may be changed during its conversion to a string.

The Execute method is more flexible than the OpenURL method, but it may require a bit of programming to complete the task. The Execute method is used to submit a command to the server for execution, and you will wait for the appropriate response from the server. In some cases, you will need to use the GetChunk or GetHeader method to retrieve the server’s response. Sometimes, the result will be a new file on your system, which you will need to open to see its contents. In other cases, the command won’t return any results, so you don’t need to worry about any special processing.

Canceling a Request

If you wish to stop your request, simply use the Cancel method. Note that you may need to clean up any files that may have been partially transferred if you use this method.

Tracking the Progress

The StateChanged event is used to track the progress of your request. See Table 11.4 for a list of the states that will be reported in this event. Many of the states will pass quickly while the connection is being established or while the command is being sent to the server. However, you can expect your program to remain in state 5 and state 7 for some time while waiting for the server to respond or send information.

TIP: When is it going to be done? You can wait for a request to be completed either by watching the StillExecuting property or by setting a trap in the StateChanged event. Using the StateChanged event is desirable when you want to display a message to the user indicating that all processing is complete (the process ended with a state of 12—everything worked okay) or that there was some sort of a problem (state of 11).

Table 11.4: State Information Returned by the StateChanged Event

State Description
0 No state information is available
1 Looking up the IP address for the remote server
2 Found the IP address for the remote server
3 Connecting to the remote server
4 Connected to the remote server
5 Requesting information from the remote server
6 The request was sent successfully to the remote server
7 Receiving a response from the remote server
8 The response was received successfully from the remote server
9 Disconnecting from the remote server
10 Disconnected from the remote server
11 An error was detected when communicating with the remote computer
12 The request was completed; all data has been received

© 1998 SYBEX Inc. All rights reserved.