To embed the results of a TCP session into one of your pages, place a [TCPConnect] context into a template, and place [TCPSend] contexts inside of that. The TCPSend steps contained inside the context execute, and any returned value displays in place of the context. Any [xxx] tags inside the context are first substituted for their real values before the TCPSend executes.
TCPConnect does nothing by itself; you must insert one or more [TCPSend] contexts inside it to perform any real work. TCPConnect establishes a connection to the TCP server program, and provides an environment for the TCPSend contexts to do their work and return text results.
Example (normally you would put the following text into a .TPL file on your server and use a web browser to link to it):
In this example, the http command equivalent to the URL "http://www.webdna.us" executes, and the results (the home page for that site) display. Notice the use of [UnURL] to send <Carriage Return><LineFeed><Carriage Return><LineFeed> as part of the TCPSend text. If you do not send the correct sequence of 2 CR/LF characters, the remote web server never returns any text, and the TCPSend times out while waiting for a response.
This example performs the equivalent of a WHOIS command which queries the Internet for information about a particular domain name. Substitute your own domain name and see what you get!
Parameter | Description |
---|---|
end |
(Optional) text to look for indicating end of line. Often [TCPSend end=%0D%0A]
is used to look for <carriage return><line feed> as the end
of line indicator, as is necessary when communicating with email POP servers
or FTP servers. Not necessary for communication with HTTP protocol, because the remote server disconnects automatically at the end of the session. |
skipheader=T |
(Optional) instructs the WebDNA engine to'strip' the MIME headers from the result |
Using 'SKIPHEADER=T' in the [TCPSend] context will instruct the WebDNA engine
to'strip' the MIME headers from the result (assuming that you are invoking an
HTTP Get or Post).
For example:
A simple HTTP GET without the SKIPHEADER set to 'T'
[text]host=[listmimeheaders name=host&exact=false][value][/listmimeheaders][/text][tcpconnect host=[host]][tcpsend]
GET [thisurl]?get=false HTTP/1.0
HOST: [host][/tcpsend][/tcpconnect]
Result:
HTTP/1.0 200 OK
Content-type: text/html
Content-Length: 29
Hello World!
With the 'SKIPHEADER=T' parameter...
[tcpconnect host=[host]][tcpsend skipheader=T]
GET [thisurl]?get=false HTTP/1.0
HOST: [host][/tcpsend][/tcpconnect]
Results:
Hello World!
The 'skipheader' option is also handy when using TCPSend to fetch a binary file from a remote server.
For Example:
[tcpconnect host=[host]] [writefile file=test.jpg][tcpsend skipheader=T]GET /[path_to_jpg] HTTP/1.0[unurl]%0D%0A[/unurl][!] [/!]Host: [host][unurl]%0D%0A%0D%0A[/unurl][!] [/!][/tcpsend][/writefile] [/tcpconnect]