Tangent API - A Simple and Efficient Way To Do Client Server Programming

What is Tangent API?
How Does Tangent API Work?
The Tangent API Model
Download
Example: Create a Chat Application Using Just Notepad
Example: Sample Application Using C#
Additional Notes for Developers
Trust in Tangent API

Additional Notes for Developers

Tangent API Data Security | Creating a Zero-Configuration Client | Interprocess Communication | Using Tangent API as an Isolated COM Reference | The Different Data Types Supported For Sending And Receiving Data | The Tangent API Threading Model

Tangent API Data Security

Since it is up to the developer what data gets sent through Tangent API, the developer is free to implement any type of security deemed necessary. This can include any form of encryption for the data that gets sent and received. Take a look at the code for the C# sample application, which includes comments on how data could be encrypted.

Creating a Zero-Configuration Client

There are methods in Tangent API that can allow a developer to create a zero-configuration client which automatically finds and connects to a running server. From a server, the StartBroadcastingIPAddress method can be used which will broadcast the server's IP address. Then from any client, the GetServerIPAddress method can be used to obtain this broadcasted server IP address. Just make sure the client and server are on the same LAN and the specified UDP port - which is a parameter to these methods - is opened on the machine where the server is running. Once the client obtains the broadcasted IP address, the client can then use it as a parameter to the ConnectToServer method. The end result is that the client machine does not need to be configured with the server machine's IP address, thus simplifying things for an end user. An example of a zero-configuration client can be seen implemented in the sample chat application.

Interprocess Communication

Tangent API was built to handle network communication, but it can just as effectively be used to handle interprocess communication. A server and client (or clients) can easily run on one machine to accomplish this. Tangent API can certainly save you development effort with interprocess communication, as the same API methods allow you to create solutions quickly and painlessly without dealing with the messy details of threading and synchronization issues. All the benefits of Tangent API apply to interprocess communication, just as well as network communication.

Using Tangent API as an Isolated COM Reference

In .NET projects, Tangent API can be added as an isolated COM reference. This basically allows a solution that uses Tangent API to be deployed to a machine where Tangent API does not have to be registered (using regsvr32). This can simplify installation/deployment of a .NET software solution that uses Tangent API. An example of a solution that uses Tangent API as an isolated COM reference can be seen in the C# sample application. Also, for more information on isolated COM components, refer to the following MSDN article.

The Different Data Types Supported For Sending And Receiving Data

Data that is sent and received is of type "object" in .NET languages, which allows the following data types to be sent and received: bool, byte, char, date, double, int, uint, short, ushort, long, ulong, single, string, byte[] (byte array), object[] (object array, where the objects can be any of the types specified here including arrays). Class instance objects are not allowed to be sent, however there is a technique that can be used to serialize a class instance into a byte array which can then be sent. See the C# sample application section for an example of this.

In C++, the following types can be sent and received: VARIANT of type VT_UI1, VT_I1, VT_UI2, VT_I2, VT_UI4, VT_I4, VT_R4, VT_R8, VT_DATE, VT_BSTR, VT_ERROR, VT_BOOL, VT_I8, VT_UI8, VT_INT, VT_UINT, VT_ARRAY | VT_UI1 (SafeArray of bytes), VT_ARRAY | VT_VARIANT (SafeArray of variants) where each element is a variant that can be of any of the types specified here. VT_DISPATCH is not allowed.

There is a maximum length allowed when sending data, and an error will result if this limit is exceeded. For a string (or VARIANT of type VT_BSTR), the maximum length is 0x007FFFFC characters. For a byte array (or VT_ARRAY | VT_UI1), the maximum bytes that can be sent is 0x00FFFFF9. For an object array (or VT_ARRAY | VT_VARIANT), the maximum objects that can be sent is variable, depending on what types of objects are in the array.

The Tangent API Threading Model

In general, when you use Tangent API, by default in most cases you won't have to worry about the threading model of Tangent API. However, to make the best use of Tangent API, it won't hurt to know the following details.

Tangent API is a COM DLL that registers as the threading model "Both". This means that it can be used in either a single-threaded apartment where event callbacks are synchronized on the GUI thread thus simplifying development, or a multi-threaded apartment where callbacks are not synchronized thus providing the best performance.

Single threaded apartment or STA, allows event callbacks to be synchronized automatically for you via Windows messaging. In .NET, this allows a developer to modify Windows Form members from within Tangent API’s event callbacks without having to invoke upon the GUI thread. By default,.NET projects are configured using the STA model. This is configured by default in the Program.cs file with the [STAThread] attribute (in C#). The STA model makes Windows Forms development easier, because the developer is ensured that event callbacks run on the same thread as the GUI, and thus GUI members can be freely modified from within callbacks. With STA, the developer is freed from the complexity of thread and data synchronization.

While STA makes development easier in Windows Forms programming, it is not as efficient as the multi-threaded apartment model or MTA. With MTA, methods can be called from any thread freely and event callbacks are fired instantly from whichever thread they are on. This does mean the developer may need to provide any data synchronization. However, MTA provides the ability to run a server with the most efficiency and high-performance, because method and event callbacks do not need to be synchronized using Windows messaging as with STA. In C# .NET projects, using the MTA model is as simple as changing the [STAThread] attribute to [MTAThread] in Program.cs. In C++, the threading model is determined by the second parameter of the function CoInitializeEx, using either COINIT_APARTMENTTHREADED for STA or COINIT_MULTITHREADED for MTA.

For additional support or any questions, send an email to support@tangentapi.com.

Tangent API Copyright © 2008-2010 Nilesh Humbad. All rights reserved.