ActiveSocket

 Product Overview

 ActiveSocket Objects:
 
 How to use

 Online Samples

 Download (.exe)

 Brochure (.pdf)

 Manual (.htm)

 Release Notes


Support

 Knowledge Base

 Forum

 Contact Support


Purchase

 Licensing

 Pricing

 Order now


Related documents

 Tutorials

 Tools


  Download ActiveSocket Network Communications Toolkit 4.1  (5094 KB - .exe file)
  Download Manual  (505 KB - .htm file)


ASP .NET (Visual Basic) SSH Secure Shell 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, TCP, UDP, HTTP and HTTPs with support for proxy servers and secure web sites, DNS, Telnet, NTP time protocol, SSH Secure Shell, RSH remote shell script interface, SNMP (Simple Network Management Protcol), SNMP Traps, SNMP Mib Browser, Sockets, WOL (Wake-On-LAN), IP-to-Country, and more.

ActiveSocket can be well integrated into ASP .NET environments.
This document describes how ActiveSocket can be integrated into ASP .NET projects.


Prerequisites

You must install and configre Internet Information Services (IIS) before using the ActiveSocket Toolkit with ASP .NET
If you don't have IIS installed, use the following steps:
  • From the Control Panel, click 'Add/Remove Programs'. Select the 'Add/Remove Windows Components' icon from the left pane, then select 'Application Server' and click on 'Details'. You can now select both 'ASP .NET' and 'Internet Information Services (IIS)'. Click 'OK' to continue installation;
  • Make sure that ASP .NET is allowed on the web server:


    (Click on the picture to enlarge)



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 ASP .NET VB Project

Launch Microsoft Visual Studio (for instance 'Microsoft Visual Studio 2005') from the Start menu. Choose 'New' from the 'File' menu and click on 'Web Site'. In the 'Web Site' dialog, select ASP .NET Web Site. Select a name for the application (for instance: 'DemoApp') and a name for the solution (for instance: 'DemoSolution'). Also, select the directory where you want to store the project (for instance: 'C:\MyProjects):

    
    (Click on the picture to enlarge)



Step 3: Refer to the ActiveSocket Library and create the objects

Now that a new project has been created, you must add a reference to the ActiveSocket library in the project to be able to use the ActiveSocket object. To do so, choose 'Add Reference...' from the 'Project' menu. In the 'Add Reference' dialog that pops up, select the 'COM' tab and select the 'ActiveSocket 3.1 Type Library' as shown in the following picture:

    
    (Click on the picture to enlarge)

Click 'OK' to close the 'Add Reference' dialog.

On top of your code, type the following line to use the ActiveSocket namespace:
   Imports ASOCKETLib
In your Main function, declare and create the following object:
   Public objSsh As Ssh
   
   objSsh    = New Ssh()







Step 4: Setup a TCP/IP connection to a remote server

You can now establish a connection to a server

The following code shows how to build a simple Telnet client using ASP.NET

global.asax.vb

Imports System.Web
Imports System.Web.SessionState
Imports ASOCKETLib

Public Class Global
    Inherits System.Web.HttpApplication

    Public objSocket As Tcp
#Region " Component Designer Generated Code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Required by the Component Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Component Designer
    'It can be modified using the Component Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
    End Sub

#End Region

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the application is started
    End Sub

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        objSocket = New Tcp()

        Session("ActiveSocket") = objSocket
    End Sub

    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires at the beginning of each request
    End Sub

    Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires upon attempting to authenticate the use
    End Sub

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when an error occurs
    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the session ends
    End Sub

    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the application ends
    End Sub

End Class


Webform1.aspx.vb

Imports ASOCKETLib
Public Class WebForm1
    Inherits System.Web.UI.Page

    Public objSocket As Socket

    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
    Protected WithEvents Label3 As System.Web.UI.WebControls.Label
    Protected WithEvents Label4 As System.Web.UI.WebControls.Label
    Protected WithEvents TextServer As System.Web.UI.WebControls.TextBox
    Protected WithEvents TextCommand As System.Web.UI.WebControls.TextBox
    Protected WithEvents TextResponse As System.Web.UI.WebControls.TextBox
    Protected WithEvents TextResult As System.Web.UI.WebControls.TextBox
    Protected WithEvents ButtonConnect As System.Web.UI.WebControls.Button
    Protected WithEvents ButtonDisconnect As System.Web.UI.WebControls.Button
    Protected WithEvents ButtonSend As System.Web.UI.WebControls.Button
    Protected WithEvents Label5 As System.Web.UI.WebControls.Label
    Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents Label6 As System.Web.UI.WebControls.Label
    Protected WithEvents Label7 As System.Web.UI.WebControls.Label
    Protected WithEvents TextPort As System.Web.UI.WebControls.TextBox
    Protected WithEvents RangeValidator1 As System.Web.UI.WebControls.RangeValidator
    Public nRetry As System.Int32

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
    End Sub

    Private Sub TextServer_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextServer.TextChanged

    End Sub

    Private Sub ButtonConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonConnect.Click
        objSocket = Session("ActiveSocket")

        objSocket.Connect(TextServer.Text, System.Int32.Parse(TextPort.Text))

        TextResult.Text = "CONNECT: ERROR " & objSocket.LastError.ToString() & " (" & objSocket.GetErrorDescription(objSocket.LastError) & ")"

        nRetry = 0

        While nRetry < 3 And objSocket.HasData = False
            objSocket.Sleep(1000)
            nRetry = nRetry + 1
        End While

        While (objSocket.HasData = True)
            TextResponse.Text = TextResponse.Text + objSocket.ReceiveString()
        End While
    End Sub

    Private Sub ButtonDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDisconnect.Click
        objSocket = Session("ActiveSocket")
        objSocket.Disconnect()
        TextResult.Text = "DISCONNECT: ERROR " & objSocket.LastError.ToString() & " (" & objSocket.GetErrorDescription(objSocket.LastError) & ")"
    End Sub

    Private Sub ButtonSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSend.Click
        objSocket = Session("ActiveSocket")
        objSocket.SendString(TextCommand.Text, 1)
        TextResult.Text = "SEND: ERROR " & objSocket.LastError.ToString() & " (" & objSocket.GetErrorDescription(objSocket.LastError) & ")"

        nRetry = 0

        While nRetry < 3 And objSocket.HasData = False
            objSocket.Sleep(1000)
            nRetry = nRetry + 1
        End While

        While (objSocket.HasData = True)
            TextResponse.Text = TextResponse.Text + objSocket.ReceiveString()
        End While
    End Sub

    Public Sub New()

    End Sub
End Class
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.


NOTE: Demo Projects are created with Microsoft Visual Studio 2002

The ActiveSocket project ships with a set of Microsoft Visual Studio .NET samples, including samples for Microsoft ASP .NET (Visual Basic). The projects are created with Microsoft Visual Studio 2002.
Users with a later version of Microsoft Visual Studio can open such a project. The Visual Studio Conversion Wizard will guide you through the process of converting the project to the version used.






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.

Copyright ©1999-2007 ActiveXperts Software. All rights reserved.