TCPConnect Context [TCPConnect Parameters]TCPSend Contexts[/TCPConnect]
Connects to a TCP port of another computer on the Internet.

To embed the results of a TCP session into one of your pages, place a [TCPConnect] context into a template, and put [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):

[TCPSend]GET / HTTP/1.0[UnURL]%0D%0A%0D%0A[/UnURL][/TCPSend]

In this example, the http command equivalent to the URL "" 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
(Required) Name or ip address of the machine to connect to. Do not insert http or ftp into the host text! TCPConnect is a very low-level connection, and it knows nothing about these protocols.
(Optional) TCP port number to connect to. If not specified, then 80 is assumed.
New for version 4.5
(Optional) Set this parameter to 'T' to create a secure socket. The port parameter should normally be set to 443 in this case.

User Contributed Notes

Alain Russell - 
07/22/2003 at 01:24:06
Not sure if this is the right section to post in .. 
A quick v5 function for providing a simple [TCPConnect] and returning the raw response. Gives you an idea of the structure of the tag:

[function name=wwwinclude]

[!] ## Set the CR/LF combination for use further down --[/!]

[!] ## split the URL ready for connect --[/!]
[text]the_url=[middle startafter=http://&endbefore=][the_url][/middle][/text]
[text]host=[middle startafter=&endbefore=/][the_url][/middle][/text]

[if "[the_url]"^"/"]
[then][text]path=[middle startafter=/&endbefore=][the_url][/middle][/text][/then]

[!] ## Do the actual connection with split paths --[/!]
[tcpconnect host=[host]&port=80]
[tcpsend skipheader=T][!]
[/!]GET /[path] HTTP/1.0[crlf][!]
[/!]Referer: http:/[thisURL][crlf][!]
[/!]Host: [host][crlf][!]


So then all you need to do is call it with:

[wwwinclude the_url=[the_url]]

Patrick McCormick - 
08/18/2009 at 18:55:02
This is a great help, Alain.

We need to add another example showing how to use TCPConnect/Send to submit form data and display a result.

This would be in a situation where you wanted to include the results of, say a CGI on another site, within your WebDNA page.

Copyright © 2008 WebDNA Software Corporation, Inc.