wwsocket::SendReceive

Sends a string to the open socket, waits for a response and returns the string response.

You should use SendReceive only on short requests that you know will retrieve typical single line responses as there's no way to know how much data is coming down. Sendreceive() simply combines a single Send() and Receive() method call and returns the result, which is very useful in typical TCP/IP command protocls as SMTP/FTP etc.

For longer content you should use the WaitFor() (if there's a terminating character) or Receive() methods (if you know the size of the output). Using Receive you'll likely have to loop to keep reading until there's no more data.

o.sendreceive(lcInput,lnSize)

Return Value

string output or "" if nothing is available (check nError)

Parameters

lcInput
Data to send.

lnSize
Size of the Receive buffer.
Defaults to nBufferSize

Example

...

*** Read the message Prefix  +OK x octets
lcResult =  THIS.oIP.SendReceive("RETR " + TRANSFORM(lnMessage) + CRLF)
IF THIS.oIP.nError # 0
   THIS.SetError("Error retrieving message: " + THIS.oIP.cErrorMsg)
   RETURN .NULL.
ENDIF
IF lcResult # "+"
   THIS.SetError(SUBSTR(lcResult,2))
   RETURN .NULL.
ENDIF   
IF EMPTY(lcResult)
   THIS.SetError("Timed out.",THIS.oIP.nError)
   RETURN .NULL.
ENDIF

See also:

Class wwsocket

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