Download ActiveSocket Network Communications Toolkit 4.1  (7643 KB - .exe file)
Download Manual  (556 KB - .htm file)
ColdFusion Telnet Sample Source Code
ActiveSocket provides an easy-to-use development interface to a variety of IP protocols.
By using ActiveSocket, you can very easily create or enhance applications with network features.
ActiveSocket features the following: ICMP, HTTP and HTTPs with support for proxy servers and secure web sites, Telnet, NTP time protocol, RSH remote shell script interface, SNMP (Simple Network Management Protcol), SNMP Traps, Sockets (TCP and UDP), WOL (Wake-On-LAN), and more.
ActiveSocket can be well integrated into ColdFusion environments.
This document describes how ActiveSocket can be integrated into ColdFusion projects.
Step 1: Download and install ActiveSocket
Download ActiveSocket from the ActiveXperts Download Site and start the installation.
The installation guides you through the installation process.
Step 2: Create a new ColdFusion document
Create a new blank webdocument with the ".cfm" extention. First of all we are going to build the form whitch commands and properties of the device can be filled in. Then we are going to make a source code that connects to the device.
Step 3: Implementation
Sending a telnet command to a server is quit simple. Setting up a telnet-connection can be done in four simple steps.
- Make the ActiveSocket object
- Fill in the properties
- Connect to the host
- Send the command
Once the object is created the rest is easy. To make the ActiveSocket object in ColdFusion you need the following code snippet:
<cfobject class="ActiveXperts.Tcp" type="com" name="objSocket" Action="Create">
Through this tag you are able to communicate through the ActiveSocket toolkit. The program has a certain amount of options witch are to be found in the
product its manual that is shipped with it. In our sample just a few of them are used. You can call to a function of the object using a “.”.
First of all I am to configure the option “logfile”. You can fill in the path and filename for the logfile. Through this file you’re able to check what
goes during the execution of the script you are writing. Use the following code to configure the logfile code:
<cfset objSocket.LogFile = “C:\temp\logfile.txt”>
Now we need to connect to the telnet server using the propertie “open”. Use the following code:
<cfset objSocket.connect(URL.host, URL.port); >
Some telnet servers are secured. When a secured server is accessed, the first two things asked are the username and the password. Because we can’t keep
the object opened, we just check if there is a username or a password filled in and we just type them down during the telnet session. To type something
down in your telnet session use the property “SendString()”:
<cfset objSocket.SendString(“SomeTextOrCommands”)>
To see the results of the commands executed, we use the ActiveSocket property “ReceiveData()”. We recommend to wait half a second before getting the
results. To wait, use the ActiveSocket property “sleep()”.
This creates the following form to send just one telnet command.

(Click on the picture to enlarge)
This creates the following code to send just one telnet command.
<!--- creating the object --->
<cfobject class="ActiveXperts.Tcp" type="com" name="objSocket" Action="Create">
<!--- set the logfile --->
<cfset objSocket.Logfile = URL.logfile>
<!--- connect to host --->
<cfscript>
objSocket.connect(URL.host, URL.port);
strResult = objSocket.LastError & ":" & objSocket.GetErrorDescription(objSocket.LastError) & "<br>";
objSocket.Sleep(1000);
receiveData();
</cfscript>
<!--- log in --->
<cfif objSocket.LastError eq 0>
<cfset username = URL.username>
<cfif username eq "">
<cfelse>
<cfscript>
objSocket.SendString(URL.username);
objSocket.SendString(URL.password);
strResult = objSocket.LastError & ":" & objSocket.GetErrorDescription(objSocket.LastError) & "<br>";
receiveData();
</cfscript>
</cfif>
<cfelse>
</cfif>
<!-- send command -->
<cfif objSocket.LastError eq 0>
<cfscript>
strCommand = URL.command;
objSocket.SendString(strCommand);
strResult = objSocket.LastError & ":" & objSocket.GetErrorDescription(objSocket.LastError) & "<br>";
WriteOutput(strCommand & ":<br>");
receiveData();
</cfscript>
<cfelse>
</cfif>
<!--- receive the results --->
<cfscript>
function receiveData(){
do{
crlf = CHR(13) & CHR(10);
strOutput = Replace(objSocket.ReceiveString(), crlf, "<br>", "ALL");
WriteOutput(strOutput & "<br>");
objSocket.Sleep(1000) ;
}
while(objSocket.HasData() eq -1);
}
</cfscript>
</div>
<br>
<table>
<tr>
<td>
<b>Results:</b>
<cfif objSocket.LastError eq 0>
<cfoutput>#strResult#</cfoutput>
<cfelse>
<cfset strResult = objSocket.LastError & ":" & objSocket.GetErrorDescription(objSocket.LastError)>
<cfoutput>#strResult#</cfoutput>
</cfif>
</td>
</tr>
</table>
<!--- close the object --->
<cfset objSocket.Disconnect()>
There are many working samples included with the product.
You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/asocket.
The ActiveSocket tool is a Network Communications ActiveX software component (SDK).
This control supports SNMP, SMTP, POP3, Telnet, TCP, NTP, RSH, HTTP, HTTPs, FTP, DNS, ICMP and more, and can be used by any Windows development platform,
including Visual Basic .NET, Visual CSharp .NET,
ASP .NET (VB,CS),
ASP,
Visual Basic,
Visual Studio/Visual C++,
Delphi,
PHP,
ColdFusion,
HTML,
VBScript and any other ActiveX/COM compliant platform. The ActiveSocket Toolkit is an ActiveXperts Software B.V. Product.
|