Technical References - [tcpsend]

A powerful feature that sends text to a TCP server program on a remote machine.

numero = 265
interpreted = N
texte = [tcpsend]Text to Send[/tcpsend] 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.

[tctsend] and [tcpconnect] will allow you to recover information from remote web pages and servers (change rates, airports arrivals and departures, payment gateways, package tracking....)

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:
[tcpconnect host=webdna.us&port=80][tcpsend]GET / HTTP/1.0[unurl]%0D%0A%0D%0A[/unurl][/tcpsend][/tcpconnect]
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.
[tcpconnect host=internic.net&port=43][tcpsend]webdna.us[unurl]%0D%0A%0D%0A[/unurl][/tcpsend][/tcpconnect]
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!
ParameterDescription
end(Optional) text to look for indicating end of line. Often [TCPSend end= ] 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.0HOST: [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.0HOST: [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%0D%0A[/unurl][!][/!]Host: [host][unurl]%0D%0A%0D%0A[/unurl][!][/!][/tcpsend][/writefile][/tcpconnect]
Another Example to get the change euro/dollar with an API: The full URL is http://rate-exchange.herokuapp.com/fetchRate?from=USD&to=EUR For this one, we have to simulate a real browser
[text]h=rate-exchange.herokuapp.com[/text][text]p=/fetchRate?from=USD&to=EUR[/text][text]n=[unurl]%0D%0A[/unurl][/text][text]USchange=[tcpconnect host=[h]&port=80][tcpsend skipheader=T]GET [p] HTTP/1.0[n][!][/!]Host: [h][n][!][/!]User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)[n][n][!][/!][/tcpsend][/tcpconnect][/text][math show=T]USdollar=[format 10.2f][middle startafter="rate":"&endbefore="][USchange][/middle][/format][/math]

As it is requested by most servers, it is important to insert the host inside the [tcpsend ][/tcpsend ] context like in the example below

[text]host=business.comcast.com[/text][text]path=/ethernet/private-line[/text][text]n=[unurl]%0D%0A[/unurl][/text][text]content=[/text][text]comcast_result=[tcpconnect host=[host]&port=443&ssl=T][tcpsend skipheader=T]GET [path] HTTP/1.0[n][!][/!]Host: [host][n][!][/!]User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)[n][!][/!]Content-Type: text/html[n][!][/!]Content-Length: [countchars][content][/countchars][n][n][!][/!][/tcpsend][/tcpconnect][/text]comcast_result=[comcast_result]
[tcpsend]Text to Send[/tcpsend]

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.

[tctsend] and [tcpconnect] will allow you to recover information from remote web pages and servers (change rates, airports arrivals and departures, payment gateways, package tracking....)


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:
[tcpconnect host=webdna.us&port=80]
[tcpsend]GET / HTTP/1.0[unurl]%0D%0A%0D%0A[/unurl][/tcpsend]
[/tcpconnect]

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.

[tcpconnect host=internic.net&port=43]
[tcpsend]webdna.us[unurl]%0D%0A%0D%0A[/unurl][/tcpsend]
[/tcpconnect]

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!

ParameterDescription
end(Optional) text to look for indicating end of line. Often [TCPSend end=
] 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%0D%0A[/unurl][!]
[/!]Host: [host][unurl]%0D%0A%0D%0A[/unurl][!]
[/!][/tcpsend][/writefile]
[/tcpconnect]


Another Example to get the change euro/dollar with an API:
The full URL is http://rate-exchange.herokuapp.com/fetchRate?from=USD&to=EUR
For this one, we have to simulate a real browser
[text]h=rate-exchange.herokuapp.com[/text]
[text]p=/fetchRate?from=USD&to=EUR[/text]
[text]n=[unurl]%0D%0A[/unurl][/text]
[text]USchange=
[tcpconnect host=[h]&port=80]
[tcpsend skipheader=T]GET [p] HTTP/1.0[n][!]
[/!]Host: [h][n][!]
[/!]User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)[n][n][!]
[/!][/tcpsend]
[/tcpconnect]
[/text]

[math show=T]USdollar=[format 10.2f][middle startafter="rate":"&endbefore="][USchange][/middle][/format][/math]


As it is requested by most servers, it is important to insert the host inside the [tcpsend ][/tcpsend ] context like in the example below



[text]host=business.comcast.com[/text]
[text]path=/ethernet/private-line[/text]
[text]n=[unurl]%0D%0A[/unurl][/text]
[text]content=[/text]

[text]comcast_result=[tcpconnect host=[host]&port=443&ssl=T]
[tcpsend skipheader=T]GET [path] HTTP/1.0[n][!]
[/!]Host: [host][n][!]
[/!]User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)[n][!]
[/!]Content-Type: text/html[n][!]
[/!]Content-Length: [countchars][content][/countchars][n][n][!]
[/!][/tcpsend]
[/tcpconnect][/text]


comcast_result=[comcast_result]



DOWNLOAD WEBDNA NOW!

Top Articles:

Tips and Tricks

A list of user-submitted tips ...

WebDNA reference

...

[biotype]

BioType is a behavioral biometrics WebDNA function based on ADGS research and development (from version 8...

Technical Change History

This Technical Change History provides a reverse chronological list of WebDNA changes...

AWS Raw WebDNA LAMP-Plus WebServer

Amazon Web Services (AWS) README for Machine Image ID...

WebDNA Modules

A list of the currently available modules...

Related Readings:

[SQLresult]

...

[random]

will display a random number...

[append]

[append db=base...

[function]

This context enables the WebDNA programmer to call a previously defined block of WebDNA code...

[removelineitem]

...

[clearlineitems]

Remove all line items from the specified shopping cart...