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)


Visual C# .NET 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.

The ActiveSocket Toolkit can be well integrated into .NET environments.
This document describes how the ActiveSocket Toolkit can be integrated into into Visual C# .NET projects.


Step 1: Download and install the ActiveSocket Toolkit

Download the 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 Visual C# .NET Project

Launch Microsoft Visual Studio (for instance 'Microsoft Visual Studio 2005') from the Start menu. Choose 'New' from the 'File' menu and click on 'Project'. In the 'New Project' dialog, select a Visual Studio template (for instance: 'Console Application'). 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 TCP/IP connection to a remote (Telnet) server

You can now use the ActiveSocket SDK to establish a connection to a server.

The following code shows how to create a simple Telnet client using Microsoft Visual C# .NET:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using ASOCKETLib;			// The actual ActiveSocket COM/OLE component

namespace TelnetGuiApp_Demo
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Button BTN_CONNECT;
		private System.Windows.Forms.Button BTN_DISCONNECT;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.TextBox TXT_COMMAND;
		private System.Windows.Forms.Button BTN_SEND;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label TXT_RESULT;
		private System.Windows.Forms.GroupBox groupBox3;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		/// 


		private Socket m_Socket;
		private System.Windows.Forms.TextBox TXT_HOST;
		System.Boolean m_bConnected = false;
		private System.Windows.Forms.Timer timer1;
		private System.Windows.Forms.TextBox TXT_RECEIVED;
		private System.Windows.Forms.Button BTN_CLOSE;
		private System.Windows.Forms.GroupBox groupbox4;
		internal System.Windows.Forms.Label Label5;
		internal System.Windows.Forms.Label label14;
		internal System.Windows.Forms.LinkLabel TXT_URLCOMP;
		internal System.Windows.Forms.PictureBox pictureBox1;
		internal System.Windows.Forms.LinkLabel TXT_URLMANUAL;
		internal System.Windows.Forms.Label label13;
		internal System.Windows.Forms.Label label12;
		internal System.Windows.Forms.Label label11;
		private System.ComponentModel.IContainer components;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 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()
		{
			this.components = new System.ComponentModel.Container();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.TXT_HOST = new System.Windows.Forms.TextBox();
			this.BTN_DISCONNECT = new System.Windows.Forms.Button();
			this.BTN_CONNECT = new System.Windows.Forms.Button();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.BTN_SEND = new System.Windows.Forms.Button();
			this.TXT_COMMAND = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.TXT_RESULT = new System.Windows.Forms.Label();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.TXT_RECEIVED = new System.Windows.Forms.TextBox();
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			this.BTN_CLOSE = new System.Windows.Forms.Button();
			this.groupbox4 = new System.Windows.Forms.GroupBox();
			this.Label5 = new System.Windows.Forms.Label();
			this.label14 = new System.Windows.Forms.Label();
			this.TXT_URLCOMP = new System.Windows.Forms.LinkLabel();
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.TXT_URLMANUAL = new System.Windows.Forms.LinkLabel();
			this.label13 = new System.Windows.Forms.Label();
			this.label12 = new System.Windows.Forms.Label();
			this.label11 = new System.Windows.Forms.Label();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.TXT_HOST,
																					this.BTN_DISCONNECT,
																					this.BTN_CONNECT});
			this.groupBox1.Location = new System.Drawing.Point(4, 4);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(316, 50);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Host";
			// 
			// TXT_HOST
			// 
			this.TXT_HOST.Location = new System.Drawing.Point(8, 20);
			this.TXT_HOST.Name = "TXT_HOST";
			this.TXT_HOST.Size = new System.Drawing.Size(160, 20);
			this.TXT_HOST.TabIndex = 2;
			this.TXT_HOST.Text = "library.uah.edu";
			// 
			// BTN_DISCONNECT
			// 
			this.BTN_DISCONNECT.Location = new System.Drawing.Point(238, 18);
			this.BTN_DISCONNECT.Name = "BTN_DISCONNECT";
			this.BTN_DISCONNECT.Size = new System.Drawing.Size(68, 23);
			this.BTN_DISCONNECT.TabIndex = 1;
			this.BTN_DISCONNECT.Text = "Disconnect";
			this.BTN_DISCONNECT.Click += new System.EventHandler(this.BTN_DISCONNECT_Click);
			// 
			// BTN_CONNECT
			// 
			this.BTN_CONNECT.Location = new System.Drawing.Point(174, 18);
			this.BTN_CONNECT.Name = "BTN_CONNECT";
			this.BTN_CONNECT.Size = new System.Drawing.Size(60, 23);
			this.BTN_CONNECT.TabIndex = 0;
			this.BTN_CONNECT.Text = "Connect";
			this.BTN_CONNECT.Click += new System.EventHandler(this.BTN_CONNECT_Click);
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.BTN_SEND,
																					this.TXT_COMMAND});
			this.groupBox2.Location = new System.Drawing.Point(6, 58);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(314, 48);
			this.groupBox2.TabIndex = 1;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "Command";
			// 
			// BTN_SEND
			// 
			this.BTN_SEND.Location = new System.Drawing.Point(172, 20);
			this.BTN_SEND.Name = "BTN_SEND";
			this.BTN_SEND.Size = new System.Drawing.Size(70, 23);
			this.BTN_SEND.TabIndex = 1;
			this.BTN_SEND.Text = "Send";
			this.BTN_SEND.Click += new System.EventHandler(this.BTN_SEND_Click);
			// 
			// TXT_COMMAND
			// 
			this.TXT_COMMAND.Location = new System.Drawing.Point(8, 20);
			this.TXT_COMMAND.Name = "TXT_COMMAND";
			this.TXT_COMMAND.Size = new System.Drawing.Size(158, 20);
			this.TXT_COMMAND.TabIndex = 0;
			this.TXT_COMMAND.Text = "guest";
			// 
			// label1
			// 
			this.label1.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.label1.Location = new System.Drawing.Point(14, 128);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(42, 14);
			this.label1.TabIndex = 2;
			this.label1.Text = "Result:";
			// 
			// TXT_RESULT
			// 
			this.TXT_RESULT.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.TXT_RESULT.Location = new System.Drawing.Point(60, 128);
			this.TXT_RESULT.Name = "TXT_RESULT";
			this.TXT_RESULT.Size = new System.Drawing.Size(254, 14);
			this.TXT_RESULT.TabIndex = 3;
			this.TXT_RESULT.Text = "(none)";
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.TXT_RECEIVED});
			this.groupBox3.Location = new System.Drawing.Point(6, 154);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(314, 194);
			this.groupBox3.TabIndex = 4;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "Received";
			// 
			// TXT_RECEIVED
			// 
			this.TXT_RECEIVED.Location = new System.Drawing.Point(8, 20);
			this.TXT_RECEIVED.Multiline = true;
			this.TXT_RECEIVED.Name = "TXT_RECEIVED";
			this.TXT_RECEIVED.Size = new System.Drawing.Size(298, 166);
			this.TXT_RECEIVED.TabIndex = 0;
			this.TXT_RECEIVED.Text = "";
			// 
			// timer1
			// 
			this.timer1.Enabled = true;
			this.timer1.Interval = 200;
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// BTN_CLOSE
			// 
			this.BTN_CLOSE.Location = new System.Drawing.Point(8, 356);
			this.BTN_CLOSE.Name = "BTN_CLOSE";
			this.BTN_CLOSE.TabIndex = 6;
			this.BTN_CLOSE.Text = "Close";
			this.BTN_CLOSE.Click += new System.EventHandler(this.BTN_CLOSE_Click);
			// 
			// groupbox4
			// 
			this.groupbox4.Location = new System.Drawing.Point(6, 110);
			this.groupbox4.Name = "groupbox4";
			this.groupbox4.Size = new System.Drawing.Size(314, 38);
			this.groupbox4.TabIndex = 7;
			this.groupbox4.TabStop = false;
			this.groupbox4.Text = "Result";
			// 
			// Label5
			// 
			this.Label5.Location = new System.Drawing.Point(7, 431);
			this.Label5.Name = "Label5";
			this.Label5.Size = new System.Drawing.Size(95, 14);
			this.Label5.TabIndex = 61;
			this.Label5.Text = "in VB.NET.";
			// 
			// label14
			// 
			this.label14.Location = new System.Drawing.Point(260, 404);
			this.label14.Name = "label14";
			this.label14.Size = new System.Drawing.Size(14, 16);
			this.label14.TabIndex = 60;
			this.label14.Text = "it.";
			// 
			// TXT_URLCOMP
			// 
			this.TXT_URLCOMP.Location = new System.Drawing.Point(209, 404);
			this.TXT_URLCOMP.Name = "TXT_URLCOMP";
			this.TXT_URLCOMP.Size = new System.Drawing.Size(53, 12);
			this.TXT_URLCOMP.TabIndex = 59;
			this.TXT_URLCOMP.TabStop = true;
			this.TXT_URLCOMP.Text = "download";
			this.TXT_URLCOMP.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.TXT_URLCOMP_LinkClicked_1);
			// 
			// pictureBox1
			// 
			this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.pictureBox1.Location = new System.Drawing.Point(7, 385);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(294, 3);
			this.pictureBox1.TabIndex = 58;
			this.pictureBox1.TabStop = false;
			// 
			// TXT_URLMANUAL
			// 
			this.TXT_URLMANUAL.Location = new System.Drawing.Point(94, 418);
			this.TXT_URLMANUAL.Name = "TXT_URLMANUAL";
			this.TXT_URLMANUAL.Size = new System.Drawing.Size(41, 12);
			this.TXT_URLMANUAL.TabIndex = 57;
			this.TXT_URLMANUAL.TabStop = true;
			this.TXT_URLMANUAL.Text = "manual";
			this.TXT_URLMANUAL.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.TXT_URLMANUAL_LinkClicked);
			// 
			// label13
			// 
			this.label13.Location = new System.Drawing.Point(129, 418);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(188, 14);
			this.label13.TabIndex = 56;
			this.label13.Text = " about how to use a COM object";
			// 
			// label12
			// 
			this.label12.Location = new System.Drawing.Point(7, 418);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(92, 14);
			this.label12.TabIndex = 55;
			this.label12.Text = "Please check our";
			// 
			// label11
			// 
			this.label11.Location = new System.Drawing.Point(7, 391);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(308, 27);
			this.label11.TabIndex = 54;
			this.label11.Text = "This application requires the ActiveSocket COM component (ASocket.dll) to be inst" +
				"alled. If not, please";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(326, 448);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.Label5,
																		  this.label14,
																		  this.TXT_URLCOMP,
																		  this.pictureBox1,
																		  this.TXT_URLMANUAL,
																		  this.label13,
																		  this.label12,
																		  this.label11,
																		  this.BTN_CLOSE,
																		  this.groupBox3,
																		  this.TXT_RESULT,
																		  this.label1,
																		  this.groupBox2,
																		  this.groupBox1,
																		  this.groupbox4});
			this.Name = "Form1";
			this.Text = "ActiveSocket Demo";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			m_Socket = new Tcp();

			m_Socket.Protocol = m_Socket.asPROTOCOL_TELNET;
		}

		private void BTN_CONNECT_Click(object sender, System.EventArgs e)
		{
			m_Socket.Connect( TXT_HOST.Text, 23 );
			TXT_RESULT.Text = m_Socket.LastError.ToString() + " (" + m_Socket.GetErrorDescription( m_Socket.LastError ) + ")";
		}

		private void BTN_DISCONNECT_Click(object sender, System.EventArgs e)
		{
			m_Socket.Disconnect();
			TXT_RESULT.Text = m_Socket.LastError.ToString() + " (" + m_Socket.GetErrorDescription( m_Socket.LastError ) + ")";
		}

		private void timer1_Tick(object sender, System.EventArgs e)
		{
			if( m_Socket.ConnectionState == m_Socket.asCONN_CONNECTED )
			{
				TXT_RECEIVED.Text += m_Socket.ReceiveString();

				BTN_DISCONNECT.Enabled = true;
				BTN_SEND.Enabled = true;
				TXT_RECEIVED.Enabled = true;
				TXT_COMMAND.Enabled = true;
			}
			else
			{
				TXT_RECEIVED.Text = "";

				BTN_DISCONNECT.Enabled = true;
				BTN_SEND.Enabled = false;
				TXT_RECEIVED.Enabled = false;
				TXT_COMMAND.Enabled = false;
			}
		}

		private void BTN_SEND_Click(object sender, System.EventArgs e)
		{
			m_Socket.SendString( TXT_COMMAND.Text,  1 );
			TXT_RESULT.Text = m_Socket.LastError.ToString() + " (" + m_Socket.GetErrorDescription( m_Socket.LastError ) + ")";
		}

		private void BTN_CLOSE_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void TXT_URLCOMP_LinkClicked_1(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			System.Diagnostics.Process.Start( "http://www.activexperts.com/files/activsocket/asocket.dll" );
		}

		private void TXT_URLMANUAL_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			System.Diagnostics.Process.Start( "http://www.activexperts.com/files/activsocket/manual.htm" );
		}
	}
}

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 Visual C# .NET. 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.