wwsocket::WaitFor

Receives data until either the provided string is found or the request times out based on the nTimeout property setting.

This method is very useful for long data streams that usually would require multiple Receive() requests. Since TCP/IP buffering determines how much data Receive() returns retrieving large data streams or data when the connection is bad usually requires a loop. Using this method avoids writing the loop syntax in your application code and wraps this functionality into this method.

o.WaitFor(lcSearchString,lnSize)

Return Value

Data containing search string

Parameters

lcSearchString
The string to search for in the result.

lnSize
Size of the Receive buffer.
Defaults to nBufferSize

Remarks

Internally several Receive() calls may be made in order to retrieve the data. If the data stream is constant (IOW the data doesn't stop coming and the search string is not found) no timeout will occur. A timeout occurs only if the data flow stops and the string requested is not found. It's recommended you set the timeout to a relatively short interval for this operation if there's a chance the data might not be found to avoid long waits when the data flow stops.

Data may not be terminated the search string - it's just guaranteed that the data is in there. Check nError for any error conditions like timeouts or that the searchstring was not found.

A good example of usage for Receive() and WaitFor() is provided in the wwPop3 class.

Example

oIP = CREATEOBJECT("wwSocket")
oIP.Connect("SomeServer.com",80)

oIP.Send("LIST" + CRLF)
lcResult = oIP.WaitFor("." + CRLF)

IF oIP.nError # 0
   ? "The request timed out..."
   RETURN
ENDIF

? lcResult

See also:

Class wwsocket | wwsocket::nBufferSize | wwsocket::Receive

© West Wind Technologies, 1996-2022 • Updated: 11/13/01
Comment or report problem with topic