WebTcpipRecvPacketsUntilData Function

Action

Receives data from Telnet server until a packet with specified data arrives.

Include file

WebAPI.bdh

Syntax

WebTcpipRecvPacketsUntilData(
    in hWeb           : number,
    in sData          : string,
    in nOptions       : number optional,
    out sDataReceived : string optional ) : boolean;

Return value

  • true if the operation was successful

  • false otherwise

Parameter Description
hWeb Valid handle to a Web connection created by WebTcpipConnect. Web connection must be in Telnet mode (by a previous WebTcpipSetTelnetMode function call) and have a screen renderer associated with it.
sData Data to be looked for in received packets.
nOptions

Comparison options; this is a case-insensitive "contains" by default, or may be one of the following:

  • TELNET_FLAG_EQUAL: Lengths of both values must match.

  • TELNET_FLAG_CASE_SENSITIVE: Comparison is performed case-sensitively.

  • TELNET_FLAG_IS_DIFFERENT: Negates the logical comparison.

  • TELNET_FLAG_IGNORE_WHITE_SPACE: All whitespaces in both compared strings are cut before comparison is performed.

  • TELNET_FLAG_CONTAINS: sText must occur within rendered screen text. (default)

  • TELNET_FLAG_FROM_LEFT: comparison is performed from the left side.

  • TELNET_FLAG_TRIM_LEFT: Leading blank spaces are trimmed from received data before comparison is performed.

  • TELNET_FLAG_TRIM_RIGHT: Trailing blanks are trimmed from received data before comparison is performed.

  • TELNET_FLAG_TRIM_BOTH: Status value is trimmed from both sides of content before comparison is performed.

  • TELNET_FLAG_FROM_RIGHT: Comparison is performed beginning from the right side.

sDataReceived Optional output data buffer where all received packets, including the matching packet, are to be placed (optional).

Example

dcltrans
  transaction TInit
  begin
    StrSetHostCP(28591); // 28591 (ISO 8859-1 Latin I)
  end TInit;

  transaction   TMain
  var
    hWeb0     : number;
    sBuffer   : string;
    sBoundary : string;
    nOption   : number;
  begin
    WebTcpipConnect(hWeb0, "My.TelnetHost.IP", WEB_PORT_TELNET);
    WebTcpipSetTelnetMode(hWeb0, TERMINAL_TYPE_ANSI, 80, 24, true, TELNET_MODEOPT_SYNC);
    WebTcpipGetOptions(hWeb0, nOption);
    if nOption <> TELNET_MODEOPT_RFC_1576 then
      WebTcpipSetOptions(hWeb0, TELNET_MODEOPT_RFC_1576);
    end;
    WebTelnetRecvCommand(hWeb0, TELNET_CMD_DO, TELNET_OPT_TerminalType);
    WebTelnetRecvCommand(hWeb0, TELNET_CMD_DO, TELNET_OPT_TerminalSpeed);
    WebTelnetRecvCommand(hWeb0, TELNET_CMD_DO, TELNET_OPT_XDisplayLocation);
    WebTelnetRecvCommand(hWeb0, TELNET_CMD_DO, TELNET_OPT_NewEnvironment);
    WebTelnetSendCommand(hWeb0, TELNET_CMD_WILL, TELNET_OPT_TerminalType);
    WebTelnetSendCommand(hWeb0, TELNET_CMD_WONT, TELNET_OPT_TerminalSpeed);
    WebTelnetSendCommand(hWeb0, TELNET_CMD_WONT, TELNET_OPT_XDisplayLocation);
    WebTelnetSendCommand(hWeb0, TELNET_CMD_WONT, TELNET_OPT_NewEnvironment);
    WebTelnetRecvSubNegotiation(hWeb0, TELNET_OPT_TerminalType);
    WebTelnetSendTerminalType(hWeb0, "vt100");
    WebTelnetRecvCommand(hWeb0, TELNET_CMD_WILL, TELNET_OPT_SuppressGoAhead);
    WebTelnetRecvCommand(hWeb0, TELNET_CMD_DO, TELNET_OPT_Echo);
    WebTelnetRecvCommand(hWeb0, TELNET_CMD_DO, TELNET_OPT_NegotiateWindowSize);
    WebTelnetRecvCommand(hWeb0, TELNET_CMD_WILL, TELNET_OPT_Status);
    WebTelnetRecvCommand(hWeb0, TELNET_CMD_DO, TELNET_OPT_RemoteFlowControl);
    WebTelnetSendCommand(hWeb0, TELNET_CMD_DO, TELNET_OPT_SuppressGoAhead);
    WebTelnetSendCommand(hWeb0, TELNET_CMD_WONT, TELNET_OPT_Echo);
    WebTelnetSendCommand(hWeb0, TELNET_CMD_WILL, TELNET_OPT_NegotiateWindowSize);
    WebTelnetSendSubNegotiation(hWeb0, TELNET_OPT_NegotiateWindowSize, "\h00500018");
    WebTelnetSendCommand(hWeb0, TELNET_CMD_DONT, TELNET_OPT_Status);
    WebTelnetSendCommand(hWeb0, TELNET_CMD_WONT, TELNET_OPT_RemoteFlowControl);
    WebTelnetRecvCommand(hWeb0, TELNET_CMD_WILL, TELNET_OPT_Echo);
    WebTcpipGetPacketBoundary(hWeb0, sBoundary);    
    WebTcpipRecvPacketsUntilData(hWeb0, "login: ");
    WebTelnetTypeKeys(hWeb0, StrToHostCP("leo"), 359.3, TELNET_FLAG_CASE_SENSITIVE);
    WebTcpipSendBin(hWeb0, "\h0D00");
    WebTcpipRecvExact(hWeb0, NULL, 390);
    WebTcpipSetPacketBoundary(hWeb0, sBoundary);
    WebTcpipRecvUntilIdle(hWeb0, NULL, 5000);
    WebTcpipSendBin(hWeb0, "\h0D000D0A");
    WebTcpipRecvPackets(hWeb0, NULL, 3);
    WebTcpipSendBin(hWeb0, "\h0D00");
    WebTcpipSendPacket(hWeb0, StrToHostCP("8") + "\h0D00");
    WebTcpipRecvClose(hWeb0, NULL);
    WebTcpipShutdown(hWeb0);
  end TMain;