ActiveSocket Network Communication Toolkit
Manual Pages


© 1999-2007 - ActiveXperts Software
http://www.activexperts.com
info@activexperts.com




Table of Contents

1. Introduction
2. System Requirements
3. Installation
4. How to use the ActiveSocket objects
5. Error Codes and Constants
6. Icmp object
7. Tcp object
8. Udp object
9. Http object
10. FtpServer / FtpFile objects
11. DnsServer / DnsRecord objects
12. Ssh object
13. Rsh object
14. Ntp object
15. SnmpManager / SnmpObject objects
16. SnmpTrapManager / SnmpTrap objects
17. SnmpMibBrowser object
18. IPtoCountry object
19. Wake-On-LAN (WOL) object
20. Samples
21. Troubleshooting
22. Purchase and Product Activation
   
Appendix A: License Agreement



1. Introduction

1.1. What is ActiveSocket?

Adding network communications capabilities to an application is never a simple matter. It requires specialized knowledge that might be outside an individual programmer's expertise. For years, VBScript, Visual Basic and Visual C++ developers have relied upon the power, flexibility and reliability of the ActiveSocket Network Communication Toolkit from ActiveXperts Software. And today, also .NET developers use this control.

With ActiveSocket you can communicate across TCP/IP networks, including the Internet. ActiveSocket provides an easy-to-use scripting interface for TCP/IP communications. By using ActiveSocket, you can very easily create or enhance applications with network features.

Use ActiveSocket to integrate the following IP protocols in your application or script:

ActiveSocket is build on top of Microsoft Winsock modules. Unlike many other toolkits on the market, it just uses the Microsoft Winsock modules, it doesn't replace them! The installation of ActiveSocket keeps your system clean.

The performance of the module is outstanding, due to its multi-threaded architecture. It has proven its strength in many business environments over the years.

ActiveSocket is a COM/OLE component, which can be used in Windows environments. ActiveSocket provides samples for many development platforms, including:

1.2. ActiveSocket Architecture

ActiveSocket is a COM/OLE object, and is build on top of Microsoft Winsock modules. The core of the ActiveSocket component consists of one file:

This component encapsulates the following objects:
The ActiveSocket component can be distributed easily to many PC's. Once you have purchased the licenses, you copy the ASocket.dll to the PCs and register the DLL on that PC.



2. System Requirements

2.1. ASP .NET, VB .NET, VC# .NET, ASP, PHP, VB, Visual C++, Delphi and more

The ActiveSocket component can be used by any of these development/scripting languages:

2.2. .NET Framework

To use ActiveSocket in an ASP .NET, Visual Basic .NET or Visual C#. NET environment, the .NET Framework must be installed on the system. The .NET Framework is part of the Windows 2003 Operating System. On Windows 2000, Windows 98, Windows ME, Windows NT, Windows Server 2003, Windows XP, it's available as a separate installation. Please visit the Technology Information for the .NET Framework page to download the .NET Framework.

2.3. Internet Information Server

Internet Information Server (IIS) Setup installs the Visual Basic Script and Java Script engines.

To run ASP pages on NT4 Servers, IIS 4.x must be installed. IIS 4.x ships with the NT4 Option Pack CD's.
To run ASP pages on Windows 2000 Servers, IIS 5.x must be installed. IIS is part of the Windows 2000 Operating System.

2.4. Internet Explorer 4.x or higher

The Internet Explorer 4.x Setup (or higher) installs the Visual Basic Script and Java Script engines.
You can use the ActiveSocket component from within the client HTML code.

2.5. Windows Scripting Host

ActiveSocket can be used in VBScript scripts. VBScripts can be used by passing the script-file as a parameter to the scripting host ( either 'cscript' or 'wscript').
WSH relies on the Visual Basic Script and Java Script engines provided with Internet Explorer 4.x or later. WSH is also installed as part of Windows 98, Windows 2000, and Internet Information Services 4.0. A separate setup program is provided for Windows 95.

2.6. Visual Basic

ActiveSocket can be used in Visual Basic 5.x or higher.

2.7. Visual C++

ActiveSocket can be used in Visual C++ 5.x or higher.

2.8. Delphi

ActiveSocket can be used in Delphi 7.x or higher.



3. Installation

The ActiveSocket package consists of 3 components; any combination of components can be installed:

3.1. Installation on a single computer

Simply run the ASocket.exe Setup program. The InstallShield wizard will guide you through the rest of the setup.
The Setup program will perform the registration of the COM/OLE component for you.

Any subsequent installation of ActiveSocket can be performed either manually or by using the Setup program.

3.2. Installation on multiple computers

Any subsequent installations can be performed using the setup program.
But since the installation of the core components is very simple, you may want to do it manually, or integrate it into your companies software distribution program.

If you choose to install the COM component manually on other machines, simply perform the following actions:



4. How to use the ActiveSocket objects

4.1. Introduction

The following code snippets (VBScript) illustrate how to use various SMS and Pager Toolkit objects.


ICMP sample (ping a remote host)

   Set objIcmp = CreateObject("ActiveXperts.Icmp")                 ' Create new Icmp instance
   For i = 1 To 4                                                  ' Prepare for 4 consecutive pings
      objIcmp.Ping "www.activexperts.com", 2000                    ' Ping host (time-out: 2000 msecs)
      If( objIcmp.LastError = 0 ) Then
         WScript.Echo "Reply from " & strHost & _                  ' Display Ping results
                      ": time=" & objIcmp.LastDuration & "ms" & _  ' Display Duration
                      " TTL=" & objIcmp.LastTtl                    ' Display TTL
      Else
         WScript.Echo "Error " & objIcmp.LastError
      End If
   Next

HTTP sample (read a web page)

   Set objHttp = CreateObject( "ActiveXperts.Http" )               ' Create new Http instance
   objHttp.ProxyServer   = "proxy01.intranet.dom"                  ' Proxy server  - if required
   objHttp.ProxyAccount  = "mjackson"                              ' Proxy authentication
   objHttp.ProxyPassword = "mjackson1"                             ' Proxy authentication
   objHttp.Connect( "www.activexperts.com/products" )              ' Connect to a web server
   WScript.Echo "Connect, result: " & objHttp.LastError
   If( objHttp.LastError <> 0 ) Then
     WScript.Quit
   End If
   strData = objHttp.ReadData                                      ' Read web page data
   WScript.Echo "ReadData, result: " & objHttp.LastError
   If( objHttp.LastError <> 0 ) Then
     WScript.Echo strData                                          ' Display web page data
   End If
   objHttp.Disconnect                                              ' Disconnectfrom the web server

FTP sample (list files in a specific directory on an FTP server)

   Set objFtpServer = CreateObject ( "ActiveXperts.FtpServer" )
   
   objFtpServer.Connect "ftp.activexperts-labs.com","anonymous","" ' Connect to the FTP server 
   Wscript.Echo "Connect, result: " & objFtpServer.LastError
   If( objFtpServer.LastError <> 0 ) Then                          ' If connect failed then quit
      WScript.Quit
   End If
   
   objFtpServer.ChangeDir "samples/ASocket/Visual Basic/Telnet"    ' Change directory
   Wscript.Echo "ChangeDir, result: " & objFtpServer.LastError
   If( objFtpServer.LastError <> 0 ) Then                          ' If ChangeDir fails then disconnect and quit
      objFtpServer.Disconnect
      WScript.Quit
   End If
   
   Set objFtpFile = objFtpServer.FindFirstFile()                   ' Iterate over all files; start with the first one
   While( objFtpServer.LastError = 0 )
      WScript.Echo "Name: " & objFtpFile.Name                      ' Display file name
      WScript.Echo "IsDirectory: " & objFtpFile.IsDirectory        ' Display directory or file
      WScript.Echo "Size: " & objFtpFile.Size                      ' Display file size
      WScript.Echo "Date: " & objFtpFile.Date                      ' Display file date
       
      ' To save the file, call the GetFile function. 
      ' strSaveAs = "C:\temp\" & objFtpFile.Name
      ' objFtpServer.GetFile objFtpFile.Name, strSaveAs
      ' Wscript.Echo "Save file, result: " & objFtpServer.LastError
   
      ' To delete a file, call the DeleteFile function. 
      ' objFtpServer.DeleteFile objFtpFile.Name
      ' Wscript.Echo "Delete, result: " & objFtpServer.LastError
   
      Set objFtpFile = objFtpServer.FindNextFile()                 ' Next file
   Wend
   
   objFtpServer.Disconnect                                         ' Disconnect

DNS sample (list all records for a specific domain)

   Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create object
   Set objConstants = CreateObject ( "ActiveXperts.ASConstants")
   
   objDnsServer.Host       = "ns1.interstroom.nl"                  ' DNS server
          
   objDnsServer.Lookup "activexperts.com", objConstants.asDNS_TYPE_ANY  ' Show all DNS records for activexperts.com
   WScript.Echo "Lookup, result: " & objDnsServer.LastError    
   If( objDnsServer.LastError <> 0 ) Then
       WScript.Quit
   End If
   
   If ( objDnsServer.IsAuthoritative = True ) Then
       WScript.Echo "Server is an authority for this domain"
   Else
       WScript.Echo "Server is not an authority for this domain"
   End If
       
   Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Iterate over all DNS records; get first record   	
   While ( objDnsServer.LastError = 0 )
       Select Case objDnsRecord.Type 
         Case objConstants.asDNS_TYPE_A
           WScript.Echo "Type             : A"
           WScript.Echo "Name             : " & objDnsRecord.Name
           WScript.Echo "IPv4 Address     : " & objDnsRecord.Address
         Case objConstants.asDNS_TYPE_AAAA
           WScript.Echo "Type             : AAAA"
           WScript.Echo "Name             : " & objDnsRecord.Name
           WScript.Echo "IPv6 Address     : " & objDnsRecord.Address
         Case objConstants.asDNS_TYPE_CNAME
           WScript.Echo "Type             : CNAME"
           WScript.Echo "Name             : " & objDnsRecord.Name
           WScript.Echo "Alias            : " & objDnsRecord.Address
         Case objConstants.asDNS_TYPE_MX 
           WScript.Echo "Type             : MX"
           WScript.Echo "Name             : " & objDnsRecord.Name
           WScript.Echo "Preference       : " & objDnsRecord.Preference
           WScript.Echo "Mail Exchange    : " & objDnsRecord.MailExchange
         Case objConstants.asDNS_TYPE_NS
           WScript.Echo "Type             : NS"
           WScript.Echo "Name             : " & objDnsRecord.Name
           WScript.Echo "Name Server      : " & objDnsRecord.NameServer
         Case objConstants.asDNS_TYPE_PTR
           WScript.Echo "Type             : PTR"
           WScript.Echo "Name             : " & objDnsRecord.Name
           WScript.Echo "Host             : " & objDnsRecord.Address
         Case objConstants.asDNS_TYPE_SOA
           WScript.Echo "Type             : SOA"
           WScript.Echo "Name             : " & objDnsRecord.Name
           WScript.Echo "Name Server      : " & objDnsRecord.NameServer
           WScript.Echo "MailBox          : " & objDnsRecord.MailBox
           WScript.Echo "Serial           : " & objDnsRecord.SerialNumber
           WScript.Echo "Refresh          : " & objDnsRecord.RefreshInterval
           WScript.Echo "Retry Interval   : " & objDnsRecord.RetryInterval
           WScript.Echo "Expiration Limit : " & objDnsRecord.ExpirationLimit
           WScript.Echo "Minimum TTL      : " & objDnsRecord.MinimumTTL
       End Select
   	
       WScript.Echo "TTL              : " & objDnsRecord.TTL
       WScript.Echo
   		
       Set objDnsRecord = objDnsServer.GetNextRecord               ' Iterate over all DNS records; get next record
   Wend

SSH sample (run a command on a remote LINUX/UNIX host in a secure way)

   Set objSsh           = CreateObject("ActiveXperts.Ssh")         ' Create an Ssh instance
   objSsh.Host          = "192.168.1.10"                           ' Hostname or IP address of remote UNIX/LINUX machine
   objSsh.UserName      = "root"                                   ' Login as 'root'
   objSsh.Password      = "topsecret"                              ' Use a password to login
   objSsh.Command       = "/bin/ls"                                ' Command to execute
   objSsh.ScriptTimeOut = 5000                                     ' Time-out (in milliseconds)
   objSsh.Run                                                      ' Execute the command now
   WScript.Echo "Run: result = " & objSsh.LastError 
   If objSsh.LastError <> 0 Then
      WScript.Quit
   End If

   ' YES, command has completed
   WScript.Echo "StdErr: " & objSsh.StdErr                         ' Print Standard Output
   WScript.Echo "StdOut: " & objSsh.StdOut                         ' Print Standard Error

   WScript.Echo "Ready."


RSH sample (run a command on a remote LINUX/UNIX host in an unsecure way)

   Set objRsh           = CreateObject("ActiveXperts.Rsh")         ' Create new Rsh instance
   objRsh.Clear
   objRsh.Host          = "192.168.1.10"                           ' Host/IP of the remote UNIX/LINUX machine
   objRsh.Command       = "/bin/ls"                                ' Command to execute on the remote machine
   objRsh.ScriptTimeOut = 5000                                     ' Time-out (in milliseconds)
   objRsh.Run                                                      ' Run the command now
   If objRsh.LastError <> 0 Then
     WScript.Echo "Error " & objRsh.LastError
	 WScript.Quit
   End If

   ' YES, command has completed
   WScript.Echo "StdErr: " & objRsh.StdErr                         ' Display stdout
   WScript.Echo "StdOut: " & objRsh.StdOut                         ' Display stderr

Client/Server TCP application (1 client script, 1 server script)

   ' C L I E N T . V B S
   Set objTcp     = CreateObject("ActiveXperts.Tcp")               ' Create new Tcp instance
   Set objConstants  = CreateObject( "ActiveXperts.ASConstants" )  ' Create a new Constants instance 
   objTcp.Protocol= objConstants.asSOCKET_PROTOCOL_RAW             ' Plain TCP/IP communications

   objTcp.Connect "127.0.0.1", 1500                                ' Connect to port 1500 on remote server
   WScript.Echo "Connect: result = " & objTcp.LastError
   If objTcp.LastError <> 0	 Then
      WScript.Echo "Error #" & objTcp.LastError & ": " & objTcp.GetErrorDescription( objTcp.LastError )
      WScript.Quit
   End If

   objTcp.SendString "This is a message"                           ' Send ASCII data
   WScript.Echo "SendString, result: " & objTcp.LastError
   objTcp.Sleep 1000                                               ' Hold script for 1000 msec

   objTcp.SendString "Quit", False                                 ' Send ASCII data
   objTcp.Disconnect                                               ' And finally, disconnect


   ' S E R V E R . V B S
   Set objTcp     = CreateObject("ActiveXperts.Tcp")               ' Create new Tcp instance
   Set objConstants  = CreateObject( "ActiveXperts.ASConstants" )  ' Create a new Constants instance 
   objTcp.Protocol= objConstants.asSOCKET_PROTOCOL_RAW             ' Plain TCP/IP communications

   objTcp.StartListening 1500                                      ' Listen on port 1500
   If objTcp.LastError <> 0 Then
      WScript.Echo "Error " & objTcp.LastError & ": " & objTcp.GetErrorDescription( objTcp.LastError )
      WScript.Quit
   End If

   Do while objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_LISTENING
      objTcp.Sleep 1000                                            ' Wait for incoming connection...
   Loop

   If objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_LISTENING Then
      str = ""                                                     ' Connection established
      Do While objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_LISTENING and str <> "Quit"

         If objTcp.HasData Then
            str = objTcp.ReceiveString
            WScript.Echo "ReceiveString: " & str
         End If
         objTcp.Sleep 100
      Loop

      objTcp.Disconnect                                            ' And finally, disconnect
   End If

Client/Server UDP application (1 client script, 1 server script)

   ' C L I E N T . V B S
   ' Create a socket instance
   Set objUdp       = CreateObject ( "ActiveXperts.Udp" )
   Set objConstants = CreateObject ( "ActiveXperts.ASConstants" )
   
   ' Write some information to console
   WScript.Echo "ActiveSocket " & objUdp.Version & " demo."
   WScript.Echo "Expiration date: " & objUdp.ExpirationDate & vbCrLf
   
   ' Open socket to send to port 1500 on remote server
   objUdp.Open "localhost", 1500, False
   WScript.Echo "Open, result: " & objUdp.LastError & _
                " (" & objUdp.GetErrorDescription( objUdp.LastError ) & ")"
   If( objUdp.LastError <> 0 ) Then
      WScript.Echo "Ready."
      WScript.Quit
   End If
   
   str = "This is just a message"
   objUdp.SendString str                                          ' Send message
   WScript.Echo "SendString '" & str & "': result = " & objUdp.LastError
   objUdp.Sleep 100
   
   str = "And this is another message"
   objUdp.SendString str                                          ' Send another message
   WScript.Echo "SendString '" & str & "': result = " & objUdp.LastError
   objUdp.Sleep 100
   
   str = "Quit"
   objUdp.SendString str                                          ' Send last message
   WScript.Echo "SendString '" & str & "': result = " & objUdp.LastError
   objUdp.Sleep 100
   
   objUdp.Close                                                   ' And finally, close the socket


   ' S E R V E R . V B S
   ' Create a socket instance
   Set objUdp       = CreateObject ( "ActiveXperts.Udp" )
   Set objConstants = CreateObject ( "ActiveXperts.ASConstants" )
   
   ' Write some information to console
   WScript.Echo "ActiveSocket " & objUdp.Version & " demo."
   WScript.Echo "Expiration date: " & objUdp.ExpirationDate & vbCrLf
   
   ' Open socket to receive UDP datagrams on port 1500 on this machine
   objUdp.Open "localhost", 1500, True
   WScript.Echo "Open, result: " & objUdp.LastError & _
                " (" & objUdp.GetErrorDescription( objUdp.LastError ) & ")"
   If( objUdp.LastError <> 0 ) Then
      WScript.Echo "Ready."
      WScript.Quit
   End If
   
   Do While str <> "Quit"
      str = objUdp.ReceiveString                                  ' Receive message	
      If( objUdp.LastError = 0 And str <> "" ) Then
          WScript.Echo "ReceiveString: " & str
      End If	
      objUdp.Sleep ( 100 )
   Loop
   
   objUdp.Close

NTP sample (query a remote time server)

   Set objNtp = CreateObject("ActiveXperts.Ntp")                   ' Create new Ntp instance
   objNtp.GetTime "fartein.ifi.uio.no"                             ' Query the time server
   If( objNtp.LastError <> 0 ) Then
     WScript.Echo "Unable to retrieve time, error: " & objNtp.LastError
     WScript.Quit
   End If

   WScript.Echo "Time on timeserver: " & objNtp.Year & _           ' Display date and time
       "/" & objNtp.Month &  "/" & objNtp.Day & _                  ' Display date and time
       " " & objNtp.Hour & ":" &  objNtp.Minute & _                ' Display date and time
       ":" &   objNtp.Second
   WScript.Echo "DifferenceTime Server / Local PC: " & _           ' Display time offset
       objNtp.LocalOffsetSeconds & " seconds"                      ' Display time offset
   End If

SNMP Walker (walk through the SNMP MIB database)

   Set objSnmpManager = CreateObject( "ActiveXperts.SnmpManager" ) ' Create a new Snmp instance
   objSnmpManager.Initialize                                       ' Initialize Snmp
   objSnmpManager.Open "192.168.1.100", "public"
   If( objSnmpManager.LastError = 0 )
     Set objSnmpObject = objSnmpManager.Get( "system.sysName.0" )  ' Get SnmpObject object
     While( objSnmpManager.LastError = 0 )
       WScript.Echo "Type:  " & objSnmpObject.Type
       WScript.Echo "Value: " & objSnmpObject.Value

       Set objSnmpObject = objSnmpManager.GetNext()                  ' Get next SnmpObject object
     End If
     objSnmpManager.Close
   End If
   objSnmpManager.Shutdown                                         ' Uninitialize Snmp

SNMP Traps (1 sender script, 1 receiver script)

   ' T R A P R E C E I V E R . V B S
   Set objTrapManager = CreateObject( "ActiveXperts.SnmpTrapManager" ) ' Create a new SnmpTrapManager instance
   objTrapManager.Initialize                                           ' Initialize SNMP
   If( objTrapManager.LastError <> 0 ) Then
      WScript.Quit
   End If
 
   objTrapManager.StartListening "public"                              ' Start listening now
   If( objTrapManager.LastError <> 0 ) Then
      objTrapManager.Shutdown                                          ' Uninitialize SNMP
      WScript.Quit
   End If

   Set objSnmpTrap = objTrapManager.GetFirstTrap                       ' Get trap

   While( objTrapManager.LastError = 0 )
      WScript.Echo "Trap from      : " & objSnmpTrap.Host
      WScript.Echo "  Community   : " & objSnmpTrap.Community

      Set objSnmpObject = objSnmpTrap.GetFirstObject      
      While( objSnmpTrap.LastError = 0 )                                ' iterate over all variables in the trap
	    	
        WScript.Echo "OID : " & objSnmpObject.OID
        WScript.Echo "Value:" & objSnmpObject.Value   
        WScript.Echo "Type:"  & GetTypeString( objSnmpObject.Type )
    	
        Set objSnmpObject = objSnmpTrap.GetNextObject
      WEnd

      Set objSnmpTrap = objTrapManager.GetNextTrap                     ' Get next trap
   WEnd  
 
   objTrapManager.StopListening                                        ' Stop listening for incoming traps
   objTrapManager.Shutdown                                             ' Uninitialize SNMP


   ' T R A P S E N D E R . V B S
   Set objSnmpTrapManager = CreateObject("ActiveXperts.SnmpTrapManager") ' Create a new SnmpTrapManager instance
   Set objSnmpTrap        = CreateObject( "ActiveXperts.SnmpTrap" )    ' Create a new SnmpTrap instance
   Set objSnmpObject      = CreateObject( "ActiveXperts.SnmpObject" )  ' Create a new SnmpObject instance
   Set objConstants       = CreateObject( "ActiveXperts.ASConstants" ) ' Create a new Constants instance 
   objSnmpTrapManager.Initialize                                       ' Initialize SNMP
   If( objSnmpTrapManager.LastError <> 0 ) Then
      WScript.Quit
   End If

   ' Set trap properties
   objSnmpTrap.Clear()
   objSnmpTrap.Host	  = "server06"
   objSnmpTrap.Community = "public"
    
   ' Add a variable to the trap
   objSnmpObject.Clear()                                               ' Clear trap object
   objSnmpObject.OID   = ".1.3.6.1.2.1.1.5.0"                          ' Set trap properties
   objSnmpObject.Type  = objConstants.asSNMP_TYPE_IPADDRESS            ' Set trap properties
   objSnmpObject.Value = "10.0.0.1"                                    ' Set trap properties 
   objSnmpTrap.AddObject objSnmpObject                                 ' Add the trap to the queue
 
   ' Add another variable to the trap
   objSnmpObject.Clear()                                               ' Clear trap object
   objSnmpObject.OID   = ".1.3.6.1.2.1.1.5.1"                          ' Set trap properties
   objSnmpObject.Type  = objConstants.asSNMP_TYPE_OCTETSTRING          ' Set trap properties
   objSnmpObject.Value = "One two three"                               ' Set trap properties 
   objSnmpTrap.AddObject objSnmpObject                                 ' Add the trap to the queue
 
   objSnmpTrapManager.Send objSnmpTrap                                 ' Send trap
   WScript.Echo "Send, result: " & objSnmpTrapManager.LastError        ' Display the result
 
   objSnmpTrapManager.Shutdown                                         ' Uninitialize SNMP

Telnet sample (connect to a web site through a telnet session)

   Set objTcp      = CreateObject("ActiveXperts.Tcp")                      ' Create new Tcp instance
   Set objConstants   = CreateObject( "ActiveXperts.ASConstants" )         ' Create a new Constants instance 
   objTcp.Protocol= objConstants.asSOCKET_PROTOCOL_TELNET                  ' Telnet communications

   objTcp.Connect "www.activexperts.com", 80                               ' Connect to web site on port 80
   Wscript.Echo "Connect,, result: " & objTcp.LastError
   If objTcp.LastError <> 0 Then
      WScript.Quit
   End If

   If objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_CONNECTED Then

     strReceived = ""                                                      ' Connection established
     objTcp.Sleep 1000
	
     objTcp.SendString "GET /activsocket/demopage/ HTTP/1.1"               ' Send string
     objTcp.SendString "Host: www.activexperts.com" & vbCrlf               ' Send string
     objTcp.Sleep 1000
	
     If objTcp.HasData Then
       strReceived = objTcp.ReceiveString                                  ' Receive data
       WScript.Echo "RECV: " & strReceived
     End If
      
     objTcp.Sleep 1000 
     objTcp.Disconnect                                                     ' Disconnect from server
   End If

IP to Country sample (maps an IP address to a country

   Set objIPC  = CreateObject( "ActiveXperts.IPtoCountry" )                ' Create a new IPtoCountry instance
   objIPC.Host = "www.activexperts.com"                                    ' Host name (or IP address) that you want to resolve
   objIPC.Query()                                                          ' Host name (or IP address) that you want to resolve
   WScript.Echo "Query, result: " & objIPC.LastError                       ' Result of Query; 0 means: success
   If objIPC.LastError = 0 Then
      WScript.Echo "Host " & strHost & " is located in " & objIPC.CountryName
   End If

Wake_On-LAN sample (Power-Up a remote computer)

   Set objWOL = CreateObject( "ActiveXperts.WOL" )                         ' Create a new WOL instance
   strMAC = "00-10-4B-BA-7A-51"
   objWOL.WakeUp strMAC                                                    ' Send magic packet to remote station identified by MAC
   WScript.Echo "WakeUp, result = " & objWOL.LastError                     ' Display the result

4.2. How to use ActiveSocket in Visual Basic .NET

First, make sure the ActiveSocket component (ASocket.dll) is registered on the machine. In case you didn't use the installation program, be sure you used the REGSVR32.EXE program to register to component.

Then, add a reference to the ActiveSocket component using the Visual Basic .NET Solution Explorer:
On top of the code, make this declaration:
    Imports ASOCKETLib
and declare and create an object like this:
    Dim objTcp As Tcp                                  ' Declaration
    objTcp = New Tcp()                                 ' Creation
You can use different ActiveSocket objects in one Visual Basic .NET application. The following code shows how to declare and create all ActiveSocket objects:
   Dim objConstants As SocketConstants                 ' Declaration
   objConstants = New SocketConstants()                ' Creation
 
   Dim objIcmp As Icmp                                 ' Declaration
   objIcmp = New Icmp()                                ' Creation
 
   Dim objTcp As Tcp                                   ' Declaration
   objTcp = New Tcp()                                  ' Creation
   
   Dim objUdp As Udp                                   ' Declaration
   objUdp = New Udp()                                  ' Creation
   
   Dim objHttp As Http                                 ' Declaration
   objHttp = New Http()                                ' Creation
 
   Dim objFtpServer As FtpServer                       ' Declaration
   objFtpServer = New FtpServer()                      ' Creation
   Dim objFtpFile As FtpFile                           ' Declaration
   objFtpFile = New FtpFile()                          ' Creation
 
   Dim objDnsServer As DnsServer                       ' Declaration
   objDnsServer = New DnsServer()                      ' Creation
   Dim objDnsRecord As DnsRecord                       ' Declaration
   objDnsRecord = New DnsRecord()                      ' Creation
 
   Dim objNtp As Ntp                                   ' Declaration
   objNtp = New Ntp()                                  ' Creation
 
   Dim objSsh As Ssh                                   ' Declaration
   objSsh = New Ssh()                                  ' Creation
 
   Dim objRsh As Rsh                                   ' Declaration
   objRsh = New Rsh()                                  ' Creation
 
   Dim objSnmpManager As SnmpManager                   ' Declaration
   objSnmpManager = New SnmpManager()                  ' Creation
   Dim objSnmpObject As SnmpObject                     ' Declaration
   objSnmpObject = New SnmpObject()                    ' Creation
 
   Dim objSnmpTrapManager As SnmpTrapManager           ' Declaration
   objSnmpTrapManager = New SnmpTrapManager()          ' Creation
   Dim objSnmpTrap As SnmpTrap                         ' Declaration
   objSnmpTrap = New SnmpTrap()                        ' Creation
 
   Dim objSnmpMib As SnmpMibBrowser                    ' Declaration
   objSnmpMib = New SnmpMibBrowser()                    ' Creation

   Dim objIPC As IPtoCountry                           ' Declaration
   objIPC = New IPtoCountry()                          ' Creation
 
   Dim objWOL As WOL                                   ' Declaration
   objWOL = New WOL()                                  ' Creation
After these declarations and creation of the object(s), you can use the objects inside your Visual Basic .NET project.

4.3. How to use ActiveSocket in Visual C# .NET

First, make sure the ActiveSocket component (ASocket.dll) is registered on the machine. In case you didn't use the installation program, be sure you used the REGSVR32.EXE program to register to component.

Then, add a reference to the object using the Visual C# Solution Explorer:
On top of your code, make this declaration:
    using ASOCKETLib;
and declare and create an object like this:
    Tcp objTcp;                                        // Declaration
    objTcp = new Tcp();                                // Creation
You can use different ActiveSocket objects in one Visual C# .NET application. The following code shows how to declare and create all ActiveSocket objects:
   SocketConstants objConstants;                       // Declaration
   objConstants = new SocketConstants();               // Creation
   
   Tcp objTcp;                                         // Declaration
   objTcp = new Tcp();                                 // Creation
 
   Udp objUdp;                                         // Declaration
   objUdp = new Udp();                                 // Creation
 
   Icmp objIcmp;                                       // Declaration
   objIcmp = new Icmp();                               // Creation
 
   Http objHttp;                                       // Declaration
   objHttp = new Http();                               // Creation
 
   FtpServer objFtpServer;                             // Declaration
   objFtpServer = new FtpServer();                     // Creation
   FtpFile objFtpFile;                                 // Declaration
   objFtpFile = new FtpFile();                         // Creation
 
   DnsServer objDnsServer;                             // Declaration
   objDnsServer = new DnsServer();                     // Creation
   DnsRecord objDnsRecord;                             // Declaration
   objDnsRecord = new DnsRecord();                     // Creation
 
   Ntp objNtp;                                         // Declaration
   objNtp = new Ntp();                                 // Creation
 
   Ssh objSsh                                          // Declaration
   objSsh = new Ssh();                                 // Creation
 
   Rsh objRsh                                          // Declaration
   objRsh = new Rsh();                                 // Creation
 
   SnmpManager objSnmpManager;                         // Declaration
   objSnmpManager = new SnmpManager();                 // Creation
   SnmpObject objSnmObject;                            // Declaration
   objSnmpObject = new SnmpObject();                   // Creation
 
   SnmpTrapManager objSnmpTrapManager;                 // Declaration
   objSnmpTrapManager = new SnmpTrapManager();         // Creation
   SnmpTrap objSnmpTrap;                               // Declaration
   objSnmpTrap = new SnmpTrap();                       // Creation
 
   SnmpMibBrowser objSnmpMib;                          // Declaration
   objSnmpMib = new SnmpMibBrowser();                  // Creation

   IPtoCountry objIPC;                                 // Declaration
   objIPC = new IPtoCountry();                         // Creation
 
   WOL objWOL;                                         // Declaration
   objWOL = new WOL();                                 // Creation
After these declarations and creation of the object(s), you can use the objects inside your Visual C# .NET code.

4.4. How to use ActiveSocket in Visual Basic

ActiveSocket can be used in Visual Basic 5.x or higher. In Visual Basic, go to the 'Project/References...' menu item and check the box next to ActiveSocket Type Library. Now, you can declare and create ActiveSocket objects.

Create a new ActiveSocket object using the 'CreateObject' function:

   Dim objConstants As ASOCKETLib.SocketConstants                           ' Declaration
   Set objConstants = CreateObject( "ActiveXperts.ASConstants" )            ' Creation
 
   Dim objIcmp As ASOCKETLib.Icmp                                           ' Declaration
   Set objIcmp = CreateObject( "ActiveXperts.Icmp" )                        ' Creation
 
   Dim objTcp As ASOCKETLib.Tcp                                             ' Declaration
   Set objTcp = CreateObject( "ActiveXperts.Tcp" )                          ' Creation
 
   Dim objUdp As ASOCKETLib.Udp                                             ' Declaration
   Set objUdp = CreateObject( "ActiveXperts.Udp" )                          ' Creation
 
   Dim objHttp As ASOCKETLib.Http                                           ' Declaration
   Set objHttp = CreateObject( "ActiveXperts.Http" )                        ' Creation
 
   Dim objFtpServer As ASOCKETLib.FtpServer                                 ' Declaration
   Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )              ' Creation
   Dim objFtpFile  As ASOCKETLib.FtpFile                                    ' Declaration
   Set objFtpFile = CreateObject( "ActiveXperts.FtpFile")                   ' Creation
 
   Dim objDnsServer As ASOCKETLib.DnsServer                                 ' Declaration
   Set objDnsServer = CreateObject( "ActiveXperts.DnsServer" )              ' Creation
   Dim objDnsRecord  As ASOCKETLib.DnsRecord                                ' Declaration
   Set objDnsRecord = CreateObject( "ActiveXperts.DnsRecord")               ' Creation
 
   Dim objNtp As ASOCKETLib.Ntp                                             ' Declaration
   Set objNtp = CreateObject( "ActiveXperts.Ntp" )                          ' Creation
 
   Dim objSsh As ASOCKETLib.Ssh                                             ' Declaration
   Set objSsh = CreateObject( "ActiveXperts.Ssh" )                          ' Creation
 
   Dim objRsh As ASOCKETLib.Rsh                                             ' Declaration
   Set objRsh = CreateObject( "ActiveXperts.Rsh" )                          ' Creation
 
   Dim objSnmpManager  As ASOCKETLib.SnmpManager                            ' Declaration
   Set objSnmpManager = CreateObject( "ActiveXperts.SnmpManager" )          ' Creation
   Dim objSnmpObject As ASOCKETLib.SnmpObject                               ' Declaration
   Set objSnmpObject = CreateObject( "ActiveXperts.SnmpObject")             ' Creation
 
   Dim objSnmpTrapManager  As ASOCKETLib.SnmpTrapManager                    ' Declaration
   Set objSnmpTrapManager = CreateObject( "ActiveXperts.SnmpTrapManager" )  ' Creation
   Dim objSnmpTrap As ASOCKETLib.SnmpTrap                                   ' Declaration
   Set objSnmpTrap = CreateObject( "ActiveXperts.SnmpTrap" )                ' Creation
 
   Dim objSnmpMib As ASOCKETLib.SnmpMibBrowser                              ' Declaration
   Set objSnmpMib = CreateObject( "ActiveXperts.SnmpMibBrowser" )           ' Creation
 
   Dim objIPC  As ASOCKETLib.IPtoCountry                                    ' Declaration
   Set objIPC = CreateObject( "ActiveXperts.IPtoCountry")                   ' Creation
 
   Dim objWOL  As ASOCKETLib.WOL                                            ' Declaration
   Set objWOL = CreateObject( "ActiveXperts.WOL")                           ' Creation
Visual Basic samples are installed during installation of the product. They can also be found on our website.

4.5. How to use ActiveSocket in Visual C++

ActiveSocket can be used in Visual C++ projects. Include the *.h and *.c file provided by ActiveXperts to bind your code to the ActiveSocket component. These files are located in the Include directory of the Visual C++ samples directory. These are the files:
Create the various ActiveSocket object instances like this:

    ISocketConstants *pConstants;         // Declaration                                         
    CoCreateInstance(CLSID_SocketConstants, NULL, CLSCTX_INPROC_SERVER, IID_ISocketConstants, (void**) &pConstants );      // Creation
 
    IIcmp *pIcmp;                         // Declaration                                         
    CoCreateInstance(CLSID_Icmp, NULL, CLSCTX_INPROC_SERVER, IID_IIcmp, (void**) &pIcmp );                     // Creation
 
    ITcp *pTcp;                           // Declaration
    CoCreateInstance(CLSID_Tcp, NULL, CLSCTX_INPROC_SERVER, IID_ITcp, (void**) &pTcp );                        // Creation
 
    IUdp *pUdp;                           // Declaration
    CoCreateInstance(CLSID_Udp, NULL, CLSCTX_INPROC_SERVER, IID_IUdp, (void**) &pUdp );                        // Creation
 
    IHttp *pHttp;                         // Declaration
    CoCreateInstance(CLSID_Http, NULL, CLSCTX_INPROC_SERVER, IID_IHttp, (void**) &pHttp );                     // Creation
 
    IFtpServer *pFtpServer;               // Declaration
    CoCreateInstance(CLSID_FtpServer, NULL, CLSCTX_INPROC_SERVER, IID_IFtpServer, (void**) &pFtpServer )       // Creation
    IFtpFile *pFtpFile;                   // Declaration
    CoCreateInstance(CLSID_FtpFile, NULL, CLSCTX_INPROC_SERVER, IID_IFtpFile, (void**) &pFtpFile )             // Creation
 
    IDnsServer *pDnsServer;               // Declaration
    CoCreateInstance(CLSID_DnsServer, NULL, CLSCTX_INPROC_SERVER, IID_IDnsServer, (void**) &pDnsServer )       // Creation
    IDnsRecord *pDnsRecord;               // Declaration
    CoCreateInstance(CLSID_DnsRecord, NULL, CLSCTX_INPROC_SERVER, IID_IDnsRecord, (void**) &pDnsRecord )       // Creation
 
    INtp *pNtp;                           // Declaration
    CoCreateInstance(CLSID_Ntp, NULL, CLSCTX_INPROC_SERVER, IID_INtp, (void**) &pNtp )                         // Creation
 
    ISsh *pSsh;                           // Declaration
    CoCreateInstance(CLSID_Ssh, NULL, CLSCTX_INPROC_SERVER, IID_ISsh, (void**) &pSsh )                         // Creation
 
    IRSh *pRsh;                           // Declaration
    CoCreateInstance(CLSID_RSh, NULL, CLSCTX_INPROC_SERVER, IID_IRSh, (void**) &pRSh )                         // Creation
 
    ISnmpManager *pSnmpManager;           // Declaration
    CoCreateInstance(CLSID_SnmpManager, NULL, CLSCTX_INPROC_SERVER, IID_ISnmpManager, (void**) &pSnmpManager ) // Creation
    ISnmpObject *pSnmpObject;             // Declaration
    CoCreateInstance(CLSID_SnmpObject, NULL, CLSCTX_INPROC_SERVER, IID_ISnmpObject, (void**) &pSnmpObject )    // Creation
 
    ISnmpTrapManager *pSnmpTrapManager;   // Declaration
    CoCreateInstance(CLSID_SnmpTrapManager, NULL, CLSCTX_INPROC_SERVER, IID_ISnmpTrapManager, (void**) &pSnmpTrapManager )// Creation
    ISnmpTrap *pSnmpTrap;                 // Declaration
    CoCreateInstance(CLSID_SnmpTrap, NULL, CLSCTX_INPROC_SERVER, IID_ISnmpTrap, (void**) &pSnmpTrap )          // Creation
 
    ISnmpMibBrowser *pSnmpMib;            // Declaration
    CoCreateInstance(CLSID_SnmpMibBrowser, NULL, CLSCTX_INPROC_SERVER, IID_ISnmpMibBrowser, (void**) &pSnmpMib ) // Creation

    IIPtoCountry *pIPC;                   // Declaration
    CoCreateInstance(CLSID_IPtoCountry, NULL, CLSCTX_INPROC_SERVER, IID_IIPtoCountry, (void**) &pIPC )          // Creation
 
    IWOL *pWol;                           // Declaration
    CoCreateInstance(CLSID_WOL, NULL, CLSCTX_INPROC_SERVER, IID_IWOL, (void**) &pWOL )                         // Creation
Visual C++ samples are installed as part of the product, but can also be found on our website.

4.6. How to use ActiveSocket in an ASP 2.x environment

    <html>
    <body>
    Version:
    <script language=vbscript runat=server>
      Set objTcp = CreateObject( "ActiveXperts.Tcp" )
      Response.Write objTcp.Version
    </script>
    </body>
    </html>

4.7. How to use ActiveSocket in Delphi 7.x or higher

Make sure the ActiveSocket Toolkit is installed on your system. For details about installation, click here.

First, add a reference to the ActiveSocket objects:

Create the various ActiveSocket object instances like this:

    objConst      : ISocketConstants;                                 { Declaration of the interface class  }
    objConst      := TSocketConstants.Create(Form1).DefaultInterface; { Creation new instance of the object }
    
    objTcp        : ITcp;                                             { Declaration of the interface class  }
    objTcp        := TTcp.Create(Form1).DefaultInterface;             { Creation new instance of the object }
  
    objUdp        : IUdp;                                             { Declaration of the interface class  }
    objUdp        := TUdp.Create(Form1).DefaultInterface;             { Creation new instance of the object }
  
    objIcmp       : IICmp;                                            { Declaration of the interface class  }
    objIcmp       := TIcmp.Create(Form1).DefaultInterface;            { Creation new instance of the object }       
  
    objHttp       : IHttp;                                            { Declaration of the interface class  }
    objHttp       := THttp.Create(Form1).DefaultInterface;            { Creation new instance of the object }       
  
    objFtpServer  : IFtpServer;                                       { Declaration of the interface class  }
    objFtpServer  := TFtpServer.Create(Form1).DefaultInterface;       { Creation new instance of the object }       
    objFtpFile    : IFtpFile;                                         { Declaration of the interface class  }
    objFtpFile    := TFtpFile.Create(Form1).DefaultInterface;         { Creation new instance of the object }       
  
    objDnsServer  : IDnsServer;                                       { Declaration of the interface class  }
    objDnsServer  := TDnsServer.Create(Form1).DefaultInterface;       { Creation new instance of the object }       
    objDnsRecord    : IDnsRecord;                                     { Declaration of the interface class  }
    objDnsRecord    := TDnsRecord.Create(Form1).DefaultInterface;     { Creation new instance of the object }       
  
    objNtp        : INtp;                                             { Declaration of the interface class  }
    objNtp        := TNtp.Create(Form1).DefaultInterface;             { Creation new instance of the object }       
  
    objSsh        : ISsh;                                             { Declaration of the interface class  }
    objSsh        := TSsh.Create(Form1).DefaultInterface;             { Creation new instance of the object }       
  
    objRsh        : IRSh;                                             { Declaration of the interface class  }
    objRsh        := TRSh.Create(Form1).DefaultInterface;             { Creation new instance of the object }       
  
    objManager    : ISnmpManager;                                     { Declaration of the interface class  }
    objManager    := TSnmpManager.Create(Form1).DefaultInterface;     { Creation new instance of the object }       
    objSnmpObject : ISnmpObject;                                      { Declaration of the interface class  }
    objSnmpObject := TSnmpObject.Create(Form1).DefaultInterface;      { Creation new instance of the object }       
  
    objManager    : ISnmpTrapManager;                                 { Declaration of the interface class  }
    objManager    := TSnmpTrapManager.Create(Form1).DefaultInterface; { Creation new instance of the object }       
    objData       : ISnmpTrapData;                                    { Declaration of the interface class  }
    objData       := TSnmpTrapData.Create(Form1).DefaultInterface;    { Creation new instance of the object }       
  
    objSnmpMib    : ISnmpMibBrowser;                                  { Declaration of the interface class  }
    objSnmpMib    := TSnmpMibBrowser.Create(Form1).DefaultInterface;  { Creation new instance of the object }       

    objIPC        : IIPtoCountry;                                     { Declaration of the interface class  }
    objIPC        := TIPtoCountry.Create(Form1).DefaultInterface;     { Creation new instance of the object }       
  
    objWOL        : IWOL;                                             { Declaration of the interface class  }
    objWOL        := TWOL.Create(Form1).DefaultInterface;             { Creation new instance of the object }       
After these declarations and creation of the object(s), you can use the objects in your Delphi projects.



5. Error Codes and Constants

5.1. Error Codes

When a function is called, the result of the function is stored in the object's 'LastError' property.
When 'LastError' is 0, it means that the last called function completed successfully; otherwise, an error occured.

The value of the LastError tells you why the function failed. All error codes are listed on the ActiveXperts web site:

www.activexperts.com/support/errorcodes (list of error codes).

Here, you can also lookup a specific error to find its description.

You can also call the 'GetErrorDescription' function of any of the objects to find the error description.

5.2. Constants

In ActiveSocket, all constants are grouped together in a separate object called SocketConstants. You must first create the Constants object before you can actually use constants:
   Set objConstants = CreateObject( "ActiveXperts.ASConstants" )
   WScript.Echo objConstants.asSOCKET_PROTOCOL_RAW
   WScript.Echo objConstants.asSOCKET_PROTOCOL_TELNET
   ...
   WScript.Echo objConstants.asSNMP_TYPE_INTEGER
   WScript.Echo objConstants.asSNMP_TYPE_IPADDRESS
   ...
 
5.2.1. Socket Protocol values

Name Description
asSOCKET_PROTOCOL_RAW TCP/IP protocol, without any protocol on top of it
asSOCKET_PROTOCOL_TELNET Telnet protocol (based on TCP/IP)

 
5.2.2. Socket Connection States

Name Description
asSOCKET_CONNSTATE_DISCONNECTED No TCP connection
asSOCKET_CONNSTATE_LISTENING Waiting for incoming connection
asSOCKET_CONNSTATE_CONNECTED Connection established


5.2.3. DNS Record Types

Name Description
asDNS_TYPE_UNDEFINED Undefined
asDNS_TYPE_A The A-record is the most basic and the most important DNS record type. They are used to translate human friendly domain names such as "www.jhsoft.com" into IP-addresses such as 212.97.55.136 (machine friendly numbers)
asDNS_TYPE_NS Authoritative name server. NS-records identify DNS servers responsible (authoritative) for a zone
asDNS_TYPE_CNAME CNAME-records are domain name aliases. Often computers on the Internet have multiple functions such as web-server, ftp-server, chat-server etc.
asDNS_TYPE_SOA Start of authority. Each zone contains exactly one SOA-record
asDNS_TYPE_PTR Domain Name Pointer. PTR-records map IP addresses to domain names (reverse of A-records)
asDNS_TYPE_MX Mail exchange. MX-records identify mail server(s) responsible for a domain name
asDNS_TYPE_AAAA IPv6 host address
asDNS_TYPE_ANY Any DNS record

 
5.2.4. SNMP Protocol Version Identifiers

Name Description
asSNMP_VERSION_V1 SNMP v1 (RFCs 1155-1157)
asSNMP_VERSION_V2C SNMP v2c (RFCs 1901-1908)


5.2.5. SNMP Data Types

Name Description
asSNMP_TYPE_UNDEFINED Undefined
asSNMP_TYPE_INTEGER Integer (16 bits)
asSNMP_TYPE_INTEGER32 Integer (32 bits)
asSNMP_TYPE_BITS Bit stream
asSNMP_TYPE_OCTETSTRING Octet string
asSNMP_TYPE_NULL Null
asSNMP_TYPE_OBJECTIDENTIFIER Object Identifier
asSNMP_TYPE_IPADDRESS IP address
asSNMP_TYPE_COUNTER32 Counter (32 bits)
asSNMP_TYPE_GAUGE32 Gauge (32 bits)
asSNMP_TYPE_TIMETICKS Time ticks
asSNMP_TYPE_OPAQUE Opaque
asSNMP_TYPE_COUNTER64 Counter (64 bits)
asSNMP_TYPE_UNSIGNED32 Unsigned integer (32 bits)


5.2.6. SNMP Trap Types

Name Description
asSNMP_TRAP_COLDSTART Cold start
asSNMP_TRAP_WARMSTART Warm start
asSNMP_TRAP_LINKDOWN Link down
asSNMP_TRAP_LINKUP Link up
asSNMP_TRAP_AUTHFAILURE Authentication failure
asSNMP_TRAP_EGPNEIGHLOSS Neighbor lost
asSNMP_TRAP_ENTERSPECIFIC Custom type


5.2.7. SNMP MIB Access constants

Name Description
asMIB_ACCESS_NOACCESS No access
asMIB_ACCESS_NOTIFY Notify access
asMIB_ACCESS_READONLY Read-only access
asMIB_ACCESS_WRITEONLY Write-only access
asMIB_ACCESS_READWRITE Rread-write access
asMIB_ACCESS_READCREATE Read-create access


5.2.7. SNMP MIB Status constants

Name Description
asMIB_STATUS_CURRENT Current
asMIB_STATUS_DEPRECATED Deprecated
asMIB_STATUS_OBSOLETE Obsolete
asMIB_STATUS_MANDATORY Mandatory




6. ICMP Object

ICMP/Ping is one of the most commonly used utilities on the Internet by people and programs, with untold millions of pings flashing every second back and forth between computers. The original PING utility stood for "Packet Internet Groper", and was a package of diagnostic utilities used by DARPA personnel to test the performance of the ARPANET. Almost every operating system includes a Ping program. It has become one of the most versatile and widely used diagnostic tools on the Internet.

ICMP/Ping sends a small packet of information containing an ICMP ECHO_REQUEST to a specified computer, which then sends an ECHO_REPLY packet in return.
You can use Ping to perform several useful network diagnostics, such as the following:
The ActiveSocket Icmp object enables you to add Icmp/Ping functionality to your program.
Here is a small example (in VBScript) to show how to use the Icmp object:
   Set objIcmp        = CreateObject("ActiveXperts.Icmp")              ' Create Icmp object
   objIcmp.Ping "www.activexperts.com", 2000                           ' Ping host; timeout 2000 ms
   If( objIcmp.LastError = 0 ) Then
     WScript.Echo "Success, duration: " & objIcmp.LastDuration & "ms"
   Else
     WScript.Echo "Error " & objIcmp.LastError & ": " & objIcmp.GetErrorDescription( objIcmp.LastError )
   End If
   WScript.Echo "Ready."

6.1. Icmp object - Properties and Functions Overview

Property Type In/Out Mand/Opt Description
Version String Out n/a Version number of ActiveSocket
ExpirationDate String Out n/a Expiration date of ActiveSocket
Ttl Number In/Out No Maximum Time To Live in next Ping call
BufferSize Number In/Out No Send buffer size
LastError Number Out n/a Result of the last called function
LastDuration Number Out n/a Reply time of the last Ping call
LastTtl Number Out n/a TTL of last Ping call

Function Description
Clear Reset all properties to the default values
Ping Ping the specified host
GetErrorDescription Get the description of the given error

6.2. Icmp object - Properties


 Version property

Description:
Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.
Example:
    Set objIcmp = CreateObject( "ActiveXperts.Icmp" )          ' Create Icmp object
    WScript.Echo  "Version: " & objIcmp.Version

 ExpirationDate property

Description:
Expiration date of ActiveSocket. This property is read-only; you cannot assign a value to it.
Once you have registered the product, the property holds the empty string ("") value.
Example:
    Set objIcmp = CreateObject( "ActiveXperts.Icmp" )          ' Create Icmp object
    WScript.Echo "ExpirationDate: " & objIcmp.ExpirationDate

 Ttl property

Description:
Time To Live to be used in the next Ping call. Value must be between 1 and 255. Default value is 255.
Example:
    Set objIcmp  = CreateObject( "ActiveXperts.Icmp" )
    objIcmp.Ttl  = 100                                         ' Use a different Time To Live than the default 255 value
    objIcmp.Ping "www.monitortools.com", 2000                  ' Ping monitortools.com, timeout after 2000 msec
    If( objIcmp.LastError = 0 ) Then
      WScript.Echo "TTL: " & objIcmp.LastTtl
    End If

 BufferSize property

Description:
Buffer size (in bytes) to be used in the next Ping call. Value must be between 0 and 8192. Default value is 32 (bytes).
Example:
    Set objIcmp         = CreateObject( "ActiveXperts.Icmp" )  ' Create Icmp object
    objIcmp.BufferSize  = 64                                   ' Use a different buffer size than the default (32 bytes)
    objIcmp.Ping "www.monitortools.com", 2000                  ' Ping monitortools.com, timeout after 2000 msec

 LastError property

Description:
The result of a previous called function. Use it to check the result of your last function call. A zero indicates: success. Any non-zero value means an error.
The GetErrorDescription function provides the error description of an error code.
For a complete list of error codes, check out the following page: www.activexperts.com/support/errorcodes.
Example:
    Set objIcmp = CreateObject( "ActiveXperts.Icmp" )          ' Create Icmp object
    objIcmp.Ping "server.mydomain.com", 2000
    WScript.Echo "LastError: " & objIcmp.LastError

 LastDuration property

Description:
The duration of the last Ping call.
The property is read-only; you cannot assign a value to it.
Example:
    Set objIcmp = CreateObject( "ActiveXperts.Icmp" )          ' Create Icmp object
    objIcmp.Ping "www.activexperts.com", 2000
    WScript.Echo "Duration of ICMP/Ping operation: " & objIcmp.LastDuration


 LastTtl property

Description:
The Time To Live value of the last Ping call. The property is read-only; you cannot assign a value to it.
The maximum Time To Live value is indicated by the Ttl property. The default maximum Time To Live value is 255, but you can assign any value between 1 and 255 to it.
Example:
    Set objIcmp = CreateObject( "ActiveXperts.Icmp" )          ' Create Icmp object
    objIcmp.Ping "www.monitortools.com", 2000
    If( objIcmp.LastError = 0 ) Then
      WScript.Echo "TTL: " & objIcmp.LastTtl
    End If

6.3. Icmp object - Functions


 Clear function

Description:
Reset all properties to their initial values. Use this function when you make consecutive calls to the Ping function. It sets LastError and LastDuration to 0.
Parameters:
None.
Return value:
Always 0.
Example:
    Set objIcmp  = CreateObject( "ActiveXperts.Icmp" )         ' Create Icmp object
    objIcmp.Ping "192.168.1.1", 2000
    objIcmp.Clear
    objIcmp.Ping "192.168.1.2", 2000

 Ping function

Description:
Ping the specified host. The function requires one parameter: the host that you want to check.
Parameters:
  • Host - Can be a host name, a NetBios name or an IP address;
  • Timeout - Timeout in milliseconds to wait for a reply.

Return value:
Always 0. Check LastError property to see if the function was completed successfully.
Example:
    Set objIcmp  = CreateObject( "ActiveXperts.Icmp" )         ' Create Icmp object
    objIcmp.Ping "192.168.1.1", 2000
    objIcmp.Clear
    objIcmp.Ping "192.168.1.2", 2000

 GetErrorDescription function

Description:
GetErrorDescription provides the error description of a given error code.
Parameters:
  • Error code.

Return value:
The error description that is associated with the given error code.
Example:
    Set objIcmp  = CreateObject( "ActiveXperts.Icmp" )         ' Create Icmp object
    objIcmp.Ping "www.thisdoesnotexist.com", 2000
    WScript.Echo "LastError: " & objIcmp.LastError
    WScript.Echo "Error description: " & objIcmp.GetErrorDescription( objIcmp.LastError )



7. Tcp object

The ActiveSocket Tcp object is based on the Transport Control protocol (TCP) protocol. Transport Control Protocol is a Transport Layer host-to-host protocol that provides reliable, connection-oriented service for IP traffic. TCP transports a stream of data in both directions between end stations. TCP does this by breaking the data into segments for transmission across a network running Internet Protocol.

You can use the ActiveSocket Tcp object basically for two purposes:

7.1. Tcp object - Client/Server communications

To establish a connection between two machines, one must act as a server and one must act as a client.
The server process waits for a client to connect. It listens on a port for an incoming connection of a client.
The client doesn't listen at all; it simply connects to a port on the server.
After a connection is established, there's no difference between client and server anymore. They can both send and receive, and they can both disconnect the session.

To be able to communicate, the server must first create a socket object, and then 'listen' on a specific TCP port to wait for an incoming connection:

    Set objTcp       = CreateObject( "ActiveXperts.Tcp" )         ' Create Tcp object
    Set objConstants = CreateObject( "ActiveXperts.ASConstants" ) ' Create constants object
    objTcp.StartListening 1500                                    ' listen on port 1500 for incoming connection
Then, the server must wait until a connection is established, i.e. when the state of the connection changes from asSOCKET_CONNSTATE_LISTENING to asSOCKET_CONNSTATE_CONNECTED:

    Do While objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_LISTENING
      ' Just do nothing
    Loop
    If objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_CONNECTED Then
      ' YES, connection established.
    End If
Once the connection has been established, server and client can communicate with eachother. They can both send and receive. To receive information, use the ReceiveString function:

    Do While objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_CONNECTED
      str = objTcp.ReceiveString
    Loop
Each time you call a function, you can check the result by checking the LastError property. For instance:

    Set objTcp       = CreateObject( "ActiveXperts.Tcp" )         ' Create Tcp object
    Set objConstants = CreateObject( "ActiveXperts.ASConstants" ) ' Create constants object
    objTcp.StartListening 1500                                    ' listen on port 1500 for incoming connection
    If objTcp.LastError = 0 Then
       ' Yes, socket is listening on the specific port for an incoming connection
    End If
On the client side, the client must connect to a server on a specific server-port:

    Set objTcp       = CreateObject( "ActiveXperts.Tcp" )         ' Create Tcp object
    Set objConstants = CreateObject( "ActiveXperts.ASConstants" ) ' Create constants object
    objTcp.Connect "remoteserver", 1500                           ' connect on port 1500
    If objTcp.LastError = 0 Then
      ' YES, connection established
    End If
Now, client and server are peers. They can both send and receive. They can send in the following way:

    objTcp.SendData "This is a message from client.vbs."          ' Send data
A process can disconnect the session anytime they want:

    objTcp.Disconnect                                             ' Disconnect

7.2. Tcp object - Telnet communications

Use the ActiveSocket Tcp object to establish a telnet session to a server or device and read its contents or configuration, for instance:
The following sample (in VBScript) reads information from the www.activexperts.com/activsocket/demopage page:
    Set objTcp      = CreateObject("ActiveXperts.Tcp")                  ' Create Tcp object
    Set objConstants= CreateObject( "ActiveXperts.ASConstants" )        ' Create constants object
    objTcp.Protocol = objConstants.asSOCKET_PROTOCOL_TELNET             ' Telnet protocol
    objTcp.Connect "www.activexperts.com", 80                           ' Connect on port 80 to remote server
    WScript.Echo "Connect, result: " & objTcp.LastError
    If objTcp.LastError <> 0 Then
      WScript.Quit
 
    If objTcp.ConnectionState = asSOCKET_CONNSTATE_CONNECTED Then.
      WScript.Echo "Connection established" & vbCrLf
      strReceived = ""
      nCounter = nCounter + 1
      objTcp.Sleep 1000
 
      objTcp.SendString "GET /activsocket/demopage/ HTTP/1.1"           ' Send data
      objTcp.SendString "Host: www.activexperts.com"                    ' Send data	
      objTcp.SendString ""                                              ' Send data (only CRLF)
 
      objTcp.Sleep 1000
 
      If objTcp.HasData Then
        strReceived = objTcp.ReceiveString                              ' Receive data	
        WScript.Echo "RECV: " & strReceived
      End If
      objTcp.Sleep 1000
      objTcp.Disconnect                                                 ' Disconnect
    End If

7.3. Tcp object - Properties and Functions

Property Type In/Out Mand/Opt Description
Version String Out n/a Version number of ActiveSocket
ExpirationDate String Out n/a Expiration date of ActiveSocket
Protocol Number In/Out O The protocol to be used
NewLine String In/Out O The character sequence that forms a newline
ConnectionState Number Out n/a The state of the connection
RemoteAddress String Out n/a The IP address and port number of the remote machine
LastError Number Out n/a Result of the last called function

Function Description
Connect Connect to a (remote) server
Disconnect Disconnect a connected session
SendString Send a string of ASCII data over the network
SendByte Send a single byte over the network
SendBytes Send raw data over the network
StartListening Start listening for an incoming connection on a specified port
StopListening Stop listening for an incoming connection
HasData Is there data available on the socket?
ReceiveString Receive incoming ASCII data on the socket
ReceiveBytes Receive incoming binary data on the socket
ReceiveByte Receive a single byte on the socket
Sleep Suspends the execution of the object for at least the specified interval
GetErrorDescription Get the description of the given error
Activate Activate the product

7.4. Tcp object - Properties


 Version property

Description:
Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.
Example:
    Set objTcp    = CreateObject( "ActiveXperts.Tcp" )              ' Create Tcp object
    Response.Write "Version: " & objTcp.Version

 ExpirationDate property

Description:
Expiration date of ActiveSocket. This property is read-only; you cannot assign a value to it.
Once you have registered the product, the property holds the empty string ("") value.
Example:
    Set objTcp    = CreateObject( "ActiveXperts.Tcp" )              ' Create Tcp object
    Response.Write "ExpirationDate: " & objTcp.ExpirationDate

 Protocol property

Description:
The protocol to be used. Can be either asSOCKET_PROTOCOL_RAW for TCP/IP without supplemental on top, or asSOCKET_PROTOCOL_TELNET.
The property is read/write.
Example:
    Set objTcp         = CreateObject( "ActiveXperts.Tcp" )         ' Create Tcp object
    Set objConstants   = CreateObject( "ActiveXperts.ASConstants" ) ' Create constants object
    objTcp.Protocol = objConstants.asSOCKET_PROTOCOL_TELNET         ' Use telnet protocol
    objTcp.Connect "server.mydomain.com", 23
    Response.Write "Connect, result: " & objTcp.LastError

 NewLine property

Description:
The character sequence that forms a newline. Default value: the CRLF (carriage return / linefeed) string. Most frequent used newline strings:
  • CR (carriage return) - a string containing only the ASCII-13 character (in C: "\r"; in VB: vbCr )
  • LF (linefeed) - a string containing only the ASCII-10 character (in C: "\n"; in VB: vbLf )
  • CRLF (carriage return / linefeed) - a string containing the ASCII-13, ASCII-10 sequence (in C: "\r\n"; in VB: vbCrLf )
A newline is used internally by two functions:
  • ReceiveString - bytes are read from the socket until a newline is detected;
  • SendString - bytes are written to the socket. Finally a newline is sent.
Example:
    Set objTcp         = CreateObject( "ActiveXperts.Tcp" )         ' Create Tcp object
    ...
    objTcp.Connect "192.168.1.1", 8081                              ' Connect
    If objTcp.LastError = 0 Then
      objTcp.NewLine  = vbCr                                        ' Use CR in the subsequent ReceiveString/SendString calls                                                                 ' transmitted by the WriteString function
      objTcp.SendString "Hello"
      If objTcp.LastError = 0 Then
        WScript.Echo "SendString was successful"
      Else
        WScript.Echo "SendString failed"
      End If
      objTcp.Disconnect
    End If

 ConnectionState property

Description:
The state of the connection. There are 3 valid Connection States.
The property is read-only; you cannot assign a value to it.
Example:
    Set objTcp         = CreateObject( "ActiveXperts.Tcp" )         ' Create Tcp object
    Set objConstants   = CreateObject( "ActiveXperts.ASConstants" ) ' Create constants object
    ...
    objTcp.StartListening 8081                                      ' Create Tcp object        
    If objTcp.LastError <> 0 Then
       WScript.Quit
    End If
    ...
    Do While objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_LISTENING
      objTcp.Sleep 1000
    Loop
    If objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_CONNECTED Then
      ' YES, connection established.
    End If

 RemoteAddress property

Description:
The IP address and port of the remote party that you are connected to.
Example:
    Set objTcp         = CreateObject( "ActiveXperts.Tcp" )         ' Create Tcp object
    ...
    objTcp.Connect "192.168.1.1", 8081                              ' Connect to 192.168.1.1 on port 8081
    WScript.Echo "Connect, result: " & objTcp.LastError             ' Print the result
    If( objTcp.LastError = 0 And objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_CONNECTED ) Then
        WScript.Echo "Connecteed to remote party: " & objTcp.RemoteAddress  ' IP:Port of the remote party
    End If

 LastError property

Description:
The result of a previous called function. Use it to check the result of your last function call. A zero indicates: success. Any non-zero value means an error.
The GetErrorDescription function provides the error description of an error code.
For a complete list of error codes, check out the following page: www.activexperts.com/support/errorcodes.
Example:
    Set objTcp     = CreateObject( "ActiveXperts.Tcp" )             ' Create Tcp object
    objTcp.Connect "server.mydomain.com", 8081
    Response.Write "Connect, result: " & objTcp.LastError

7.5. Tcp object - Functions


 Connect function

Description:
Make a connection to a (remote) server on a TCP port.
Parameters:
  • Host; DNS hostname, a NetBIOS name or an IP address;
  • TCP port.
Return value:
Always 0. Check LastError property to see if the function was completed successfully.
Example:
    Set objTcp         = CreateObject( "ActiveXperts.Tcp" )         ' Create Tcp object
    ...
    objTcp.Connect "192.168.1.1", 8081                              ' Connect to 192.168.1.1 on port 8081
    WScript.Echo "Connect, result: " & objTcp.LastError             ' Print the result
Example:
    objTcp.Connect "myserver", 8081

 Disconnect function

Description:
Disconnect an active TCP connection.
The function doesn't require any parameters
Parameters:
None.
Return value:
Always 0. Check LastError property to see if the function was completed successfully.
Example:
    Set objTcp         = CreateObject( "ActiveXperts.Tcp" )         ' Create Tcp object
    ...
    objTcp.Connect "192.168.1.1", 8081                              ' Connect
    If objTcp.LastError = 0 Then
      objTcp.SendData "Hello"
      objTcp.Disconnect                                             ' Disconnect
    End If

 SendString function

Description:
This function sends a string of printable ASCII data to the (remote) server.
Telnet functions need a NewLine after the data string. ActiveSocket will automatically append the NewLine to the string.
Use the SendByte or SendBytes functions to send binary data or strings without NewLine sequence over the network.
Parameters:
  • Datastring - the string you want to send.
Return value:
Always 0. Check LastError property to see if the function was completed successfully.
Example:
    Set objTcp         = CreateObject( "ActiveXperts.Tcp" )         ' Create Tcp object
    ...
    objTcp.Connect "192.168.1.1", 8081                              ' Connect
    If objTcp.LastError = 0 Then
      objTcp.SendString "Hello"
      If