A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.cfengine.com/latest/reference-functions-readtcp.html below:

readtcp - CFEngine 3.26 Docs

Prototype: readtcp(hostnameip, port, sendstring, maxbytes)

Return type: string

The return value is cached.

Description: Connects to tcp port of hostnameip, sends sendstring, reads at most maxbytes from the response and returns those.

If the send string is empty, no data are sent or received from the socket. Then the function only tests whether the TCP port is alive and returns an empty string.

Not all Unix TCP read operations respond to signals for interruption, so poorly formed requests can block the cf-agent process. Always test TCP connections fully before deploying.

Arguments:

Example:

code

body common control
{
      bundlesequence => { "example" };
}

bundle agent example
{
  vars:

      "my80" string => readtcp("myserver.com","80","GET /index.html HTTP/1.1$(const.r)$(const.n)Host: myserver.com$(const.r)$(const.n)$(const.r)$(const.n)",20);

  classes:

      "server_ok" expression => regcmp("[^\n]*200 OK.*\n.*","$(my80)");

  reports:

    server_ok::

      "Server is alive";

    !server_ok::

      "Server is not responding - got $(my80)";
}

Output:

Notes: Note that on some systems the timeout mechanism does not seem to successfully interrupt the waiting system calls so this might hang if you send an incorrect query string. This should not happen, but the cause has yet to be diagnosed.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4