Creating Components Dynamically
When using Visual Studio .NET, the components included in PowerTCP SSL Sockets for .NET can either be used as a component (see Placing Components on a Form for more information) or added as a reference. If you are using one of the components as a reference, there are a few extra steps you must take, namely:
- You must instantiate your own event handlers.
- You must create and add a licenses.licx file to the project.
The following steps illustrate how to add a component as a reference within Visual Studio .NET
To add the a component as a reference within Visual Studio .NET, use the following steps (the following steps demonstrate adding the Tcp component):
- Create a project as described in Creating A Project .
- Add the Tcp component as a reference. To do this right-click the References folder in the Solution Explorer and choose Add Reference (see the screen shot below). If the Solution Explorer is not visible, navigate to the View menu and choose Solution Explorer.
- You must add a licenses.licx file to the project. (See Creating the Licenses.licx File for more information).
- Make a quick application to test. Drag a button onto the form.
- Create an instance of the Tcp component within the button "on-click" event handler.
[C#]
Dart.PowerTCP.SslSockets.Tcp tcp1 = new Dart.PowerTCP.SslSockets.Tcp();
[Visual Basic]
Dim Dart.PowerTCP.SslSockets.Tcp1 as New Dart.PowerTCP.SslSockets.Tcp();
- Add the following code to the button "on-click" event handler immediately after the code to create the Tcp component.
[C#]
// Connect to an Echo server (typically port 7)
tcp1.Connect("myserver", 7);
// Send some data
tcp1.Send("test");
// Receive the echoed data
Segment seg = tcp1.Receive();
// In the Echo protocol, the server waits until the client closes the connection.
tcp1.Close();
// Display the data received (should be "test")
Debug.WriteLine(seg.ToString());
[Visual Basic]
' Connect to an Echo server (typically port 7)
Tcp1.Connect("myserver", 7)
' Send some data
Tcp1.Send("test")
' Receive the echoed data
Dim seg As Segment = Tcp1.Receive()
' In the Echo protocol, the server waits until the client closes the connection.
Tcp1.Close()
' Display the data received (should be "test")
Debug.WriteLine(seg.ToString())
- Add a licenses.licx file to the project as described in Creating the Licenses.licx File.
- Navigate to the Debug menu and choose Start. The application will compile and execute.
- Note: This example shows usage without events. If you use a component as a reference you will have to create your own event handlers. To do this, see the Creating Components Dynamically topic.
In This Section
- Creating a Project
- This topic demonstrates how to create a new Windows project in Visual Studio .NET.
- Placing Components on a Form
- This topic demonstrates how to create and use a control using Visual Studio .NET.
- Creating Components Dynamically
- This topic demonstrates how to add a component as a reference using Visual Studio .NET.
- Creating Custom Dlls
- Discusses the steps required when creating a dll that uses a PowerTCP control.
- Using Components Outside of Visual Studio
- This topic discusses the use of the components without Visual Studio.
- Using Events within the Visual Studio .NET Environment
- Describes how to use PowerTCP events within the Visual Studio .NET environment.
- Using Events when a Component is Created Dynamically
- Describes the extra steps required to use events when using a PowerTCP component as a reference.
Sockets Using Menublock
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.