wodTelnetDLX ActiveX Control - WaitFor Method
      
 

Description

Waits and reads data until pattern is found.


Return Type

A String value.  


Syntax

object.WaitFor (Pattern, [Timeout])



The WaitFor Method syntax has these parts:

Part Description
object An expression evaluating to an object of type wodTelnetDLX.
Pattern Required. A String value. Data you expect to be received as 'end of waitfor' command.
Timeout Optional. A Variant value. Inactivity timeout to wait, in seconds.

Remarks

This method is only available in COM version of the component.

WaitFor method will wait and receive data from the server, until specified Pattern is found, or timeout expires. If timeout is not specified, then default one is used, as defined in Timeout property. If timeout expires, you will get an error, but you will still be able to receive data that arrived in the meantime using Receive method call.

NOTE: this method works only when Blocking property is set to True.

Very common way for using WaitFor method is to read all data that servers sends us upon connection. Usually you will know what exactly you need to receive, so you can use this command to help you, like this:

TelnetDLX1.HostName = "yourhost"
TelnetDLX1.Login = "tester"
TelnetDLX1.Password = "weonlydo"
TelnetDLX1.Protocol = SSHAuto
TelnetDLX1.Blocking = True
TelnetDLX1.Connect
Debug.Print TelnetDLX.WaitFor("joe@debian")

This sample will block until 'joe@debian' is found within received text. If it's not found in reasonable time (until timeout expires) you will still be able to Receive last 16k of data - just to check why it failed.

Since version 2.0.0.2, Timeout can be specified as negative value too. When set up this way, wodTelnetDLX will use it as 'absolute timeout' - component will return from WaitFor method call in specified time no matter if it was idle or busy in that time. This change was made to prevent wodTelnetDLX from freezing if expected response is never received. wodTelnetDLX.Timeout property will still hold regular, 'inactivity timeout' value as it was before.
One sidenote - it is almost impossible to predict what state of the session will be when this 'absolute timeout' expires. You may still receive big amount of data that will confuse your client, depending on what was going on while WaitFor method was running.

Note - this command internally disables PromptReceived event and Received event since it's taking control on what's received from the server.

You can also provide regular expression to be searched in received data instead of exact value. You should prepend your Waitfor argument with regex: text so wodTelnetDLX knows you are using regular expression. For example, you can use it like this:

Debug.Print Telnet1.WaitFor("regex:[\$%#>] $")

above regular expression will match when:

  • $, %, #, or > found
  • space
  • end of line

typically, our previous sample joe@somehost:-$<SPACE> does match above regex. But, hey, feel free to use something more complex such as:

Debug.Print Telnet1.WaitFor("regex:[a-zA-z0-9]+@[a-zA-z0-9]+:[a-zA-z0-9-/]+[\$%#>] $")

or using extended PERL syntax

Debug.Print Telnet1.WaitFor("regex:\w+@\w+:\S+\$ $")

just don't forget to put 'regex:' text in front of regular expression, otherwise wodTelnetDLX will search for exact match of specified pattern. PCRE (www.pcre.org) library is used for regex support.