This project includes a demo client showing integration between .NET Standard client API for Lightstreamer and RTD Server for Excel.
View live demo
(download deploy.zip; extract it; follow the readme)
Real-Time Data (RTD) is a technology introduced in Microsoft Excel starting from 2002, aimed at replacing DDE for updating spreadsheets in real-time.
This demo is made up of a DLL library that acts as an RTD Server, which receives updates from Lightstreamer Server on one side and injects them into Excel on the other side.
The library has been developed with C# (full source code is provided, see below).
It leverages the .NET Standard Client API for Lightstreamer to subscribe to 30 stock items and the Microsoft.Office.Interop.Excel to set up the RTD server.
The main class is RtdServer, found in RtdServer.cs, which contains an implementation of the IRtdServer interface that serves as a bridge for communication between Excel and the Lightstreamer server.
The RTD function (https://learn.microsoft.com/en-us/office/troubleshoot/excel/set-up-realtimedata-function) uses the following syntax
=RTD(RealTimeServerProgID,ServerName,Topic1,[Topic2], ...)
So, the first parameter is the identifier of the RTD server installed on the local system who will provide the data.
It is registered in the C# code and for this demo is defined as: lightstreamer.rtdnew23
The ServerName parameter is not used by the demo and the following parameters are a free list of values called topics which should represent the value required by the excel sheet to valorise the cells.
In the demo the first topic of the list is used as a selector.
The 'CONFIG' value is a special case that once received by the RTDServer triggers the connection to the Lightstreamer server. Please look at A1 cell in the Excel sheet:
=rtd("lightstreamer.rtdnew23",,"CONFIG","http://localhost","8080","WELCOME","STOCKS","user_test","o93ujDNJasf,ajfih393!_ard3sfaklj_sjsijhdf3934eifaskik(2332334yh32rdusjdsshkahkhgfasif24egfwebkjbcfasik")
The demo uses the values of the other topics to initialize the connection, respectively:
- Lightstreamer server url (Topic2),
- port number (Topic3),
- Adapter Set name (Topic4),
- Data Adapter name (Topic5),
- user (Topic6),
- password (Topic7).
And return the current status of the connection with the Lightstreamer server.
The 'OPTIONS' value is a special case that once received by the RTDServer leverages some specific tuning for Lightstreamer. Currently it is possible to configure:
- the max frequency for each subscriptions,
max_frequency
: Subscription.RequestedMaxFrequency - the transport for the communication with the Lightstreamer server,
forced_transport
: ConnectionOptions.ForcedTransport - the stalled timeout,
stalled_timeout
: ConnectionOptions.StalledTimeout - a proxy,
proxy
: ConnectionOptions.Proxy
Double check the cells of column A (A2, A3, A7) for some examples of configurations.
Instead, regarding the cells in the demo with stock market tickers, the formula is as follows:
=rtd("lightstreamer.rtdnew23",,"item1","stock_name")
where Topic1 and Topic2 are respectively the name of the Item and the field we want to display in the cell and therefore, they must be subscribed through the client session of Lightstreamer.
Once all the items and fields required by the Excel sheet are subscribed and their subscriptions are submitted, the demo will start receiving real-time updates from the Lightstreamer server. These updates are collected in a temporary data structure and are dequeued whenever the RefreshData function is called.
LSConnect.cs, StocklistConnectionListener.cs, and StocklistSubListener.cs contain classes used to interface to the Lightstreamer .NET Standard Client library.
The Demo produces a log file, TestRTD.log, with information about the interaction both with the Excel sheet and the Lightsgtreamer server. Check out the sources for further explanations.
NOTE: Not all the functionalities of the Lightstreamer .NET Client & Local RTD Server for Excel demo are exposed by the classes listed above. You can easily expand those functionalities using the PCL/C# Client API as a reference: http://www.lightstreamer.com/api/ls-pcl-client/latest/.
If you want to install a version of this demo pointing to your local Lightstreamer Server, follow these steps:
- Note that, as prerequisite:
- Launch Lightstreamer Server.
- Download the deploy.zip file that you can find in the latest release of this project and extract the
TestRTD
folder. - Execute the
ExcelDemoLauncher.bat
command bat from thenet7.0
ornet7.0-x64
folder depending your Excel is 32 or 64 bit.- Since a dll registration is involved the batch file should be launched with administrator privileges.
- The spreadsheet will activate the Lightstreamer RTD library, and several cells will start changing in real-time.
NOTE: You may also use the sources included in this project with another Microsoft IDE or without any IDE but such an approach is not covered in this readme.
The project also includes a solution and a project designed for Visual Studio, we used the 2022 version. Just build the Lightstreamer-example-StockList-client-rtd project to get the dll ready to use. The reference framework for the project is net7.0 and it is also necessary to specify the target platform (x86 or x64) according to the version of Excel installed. The RTD server contained in the dll must be COM registered in order to activate. The following commands must be executed from an elevated command prompt:
Register: regsvr32.exe Lightstreamer-example-StockList-client-rtd.comhost.dll
Unregister: regsvr32.exe /u Lightstreamer-example-StockList-client-rtd.comhost.dll
Once Lightstreamer-example-StockList-client-rtd.comhost.dll
is registered, ExcelDemo_New.xlsx
has to be opened.
If the registration was successful, Excel will load the RTD server, and real-time data will start to be delivered to it.
Please note that the RTD technology works on top of DCOM, this means that you could even deploy a centralized remote RTD Server that can be used across your network. In the case of this demo, both RTD Server and Excel will run on the same local computer.
Internet connection is required to make the RTD Server, controlling a Lightstreamer connection, being able to deliver real-time data to Excel.
Obviously, you could test the application against your Lightstreamer server installed somewhere, but in this case, you have to change the paramters of RTD function in A1
cell of the Excel sheet.
- Lightstreamer - Stock-List Demo - Java Adapter
- Lightstreamer - Reusable Metadata Adapters - Java Adapter
- Lightstreamer - Stock-List Demos - HTML Clients
- Lightstreamer - Basic Stock-List Demo - jQuery (jqGrid) Client
- Lightstreamer - Stock-List Demo - Dojo Toolkit Client
- Lightstreamer - Basic Stock-List Demo - .NET Client
- Lightstreamer - Basic Stock-List Demo - Java SE (Swing) Client
- Compatible with Lighstreaer .NET Standard Client since version 6.0
- Compatible with .NET 7
- For a version of this demo compatible with Lightstreamer .NET PCL Client Library version 3.0.0 or lower please check out this tag deploy_pcl.
- Ensure that .NET Standard Client API is supported by Lightstreamer Server license configuration.