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 (C#) 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 ASP.NET environments.
This document describes how ActiveSocket can be integrated into into ASP .NET (C#) projects.


Prerequisites

You must install and configure 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 the ActiveSocket Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.



Step 2: Create a new ASP .NET C# 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 toolkit 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:
   using ASOCKETLib;
In your Main function, declare and create the following object:
   public Tcp m_objSocket;

   m_objSocket = new Tcp();


Step 4: Establish a connection to a remote server

You can now establish a connection with a remote server.

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

global.asax.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using ASOCKETLib;

namespace ASocketDemo 
{
	/// <summary>
	/// Summary description for Global.
	/// </summary>
	public class Global : System.Web.HttpApplication
	{
		protected Socket objSocket;

		public Global()
		{
			InitializeComponent();
		}	
		
		protected void Application_Start(Object sender, EventArgs e)
		{

		}
 
		protected void Session_Start(Object sender, EventArgs e)
		{
			objSocket = new Tcp();

			Session["ActiveSocket"] = objSocket;
		}

		protected void Application_BeginRequest(Object sender, EventArgs e)
		{

		}

		protected void Application_EndRequest(Object sender, EventArgs e)
		{

		}

		protected void Application_AuthenticateRequest(Object sender, EventArgs e)
		{

		}

		protected void Application_Error(Object sender, EventArgs e)
		{

		}

		protected void Session_End(Object sender, EventArgs e)
		{

		}

		protected void Application_End(Object sender, EventArgs e)
		{

		}
			
		#region Web Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
		}
		#endregion
	}
}


WebForm1.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ASOCKETLib;

namespace ASocketDemo
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected Tcp objSocket;
		protected Int32	nRetry;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Label Label7;
		protected System.Web.UI.WebControls.TextBox TextPort;
		protected System.Web.UI.WebControls.RangeValidator RangeValidator1;
		protected System.Web.UI.WebControls.TextBox TextServer;
		protected System.Web.UI.WebControls.TextBox TextCommand;
		protected System.Web.UI.WebControls.TextBox TextResponse;
		protected System.Web.UI.WebControls.TextBox TextResult;
		protected System.Web.UI.WebControls.Button ButtonConnect;
		protected System.Web.UI.WebControls.Button ButtonDisconnect;
		protected System.Web.UI.WebControls.Button ButtonSend;
		protected System.Web.UI.WebControls.Label Label5;
		protected System.Web.UI.WebControls.HyperLink HyperLink1;
		protected System.Web.UI.WebControls.Label Label6;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.ButtonConnect.Click += new System.EventHandler(this.ButtonConnect_Click);
			this.ButtonDisconnect.Click += new System.EventHandler(this.ButtonDisconnect_Click);
			this.ButtonSend.Click += new System.EventHandler(this.ButtonSend_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void ButtonConnect_Click(object sender, System.EventArgs e)
		{
			objSocket = ( Tcp ) 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 && objSocket.HasData () == 0)
			{
				objSocket.Sleep(1000);
				nRetry++;
			}

			while ( objSocket.HasData () == -1 )
			{
				TextResponse.Text = TextResponse.Text + objSocket.ReceiveString();
			}
		}

		private void ButtonDisconnect_Click(object sender, System.EventArgs e)
		{
			objSocket = ( Socket ) Session ["ActiveSocket"];
			objSocket.Disconnect();

			TextResult.Text = "DISCONNECT: ERROR " + objSocket.LastError.ToString() + " (" + objSocket.GetErrorDescription(objSocket.LastError) + ")";
		}

		private void ButtonSend_Click(object sender, System.EventArgs e)
		{
			objSocket = ( Socket ) Session["ActiveSocket"];
			objSocket.SendString(TextCommand.Text, 1);
			TextResult.Text = "SEND: ERROR " + objSocket.LastError.ToString() + " (" + objSocket.GetErrorDescription(objSocket.LastError) + ")";

			while ( nRetry < 3 && objSocket.HasData () ==  0 )
			{
				objSocket.Sleep(1000);
				nRetry++;
			}

			while ( objSocket.HasData () == -1 )
			{
				TextResponse.Text = TextResponse.Text + objSocket.ReceiveString();
			}
		}
	}
}
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 project ships with a set of Microsoft Visual Studio .NET samples, including samples for Microsoft ASP .NET C#. 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.