Furthermore, the new library has transitioned to the TLCP protocol for the communication with the Lightstreamer server. The TLCP protocol is designed around unifying principles like simplicity of parsing, uniformity of responses, and support for multiple transports. Indeed, the inclusion of TLCP opens the way for the support of WebSockets as primary transport.
WebSockets provide a persistent, full-duplex communication channel between the client and the Server, reducing connection overhead to a minimum and hence improving the throughput, specifically in high-traffic situations. WebSockets are now tried as first transport. When a WebSocket connection is available, the client reports the status of "CONNECTED:WS-STREAMING". The client reverts automatically to HTTP streaming in case it is not available.
The API allows subscribing to real-time data pushed by the server and to send any message to the server. The library offers automatic recovery from connection failures, automatic selection of the best available transport, and full decoupling of subscription and connection operations. The subscriptions are always meant as subscriptions "to the LightstreamerClient", not "to the Server"; the LightstreamerClient is responsible for forwarding the subscriptions to the Server and re-forwarding all the subscriptions whenever the connection is broken and then reopened.
Finally, the new library also introduces automatic management of the second level for COMMAND mode subscriptions.
Before starting a brief overview of the use of the library with snippets of code showing the main features (yes, don't worry, there is also the new version of our well-known Stock-List Demo rewritten with the new APIs), please consider these as basic reference points:
- Public API documentation: https://www.lightstreamer.com/api/ls-dotnetstandard-client/latest/
- The package of the library is available from NuGet: https://www.nuget.org/packages/Lightstreamer.DotNetStandard.Client/
- The complete sources of the library: https://github.com/Lightstreamer/Lightstreamer-lib-client-dotne
Let's Quickstart with the Code
To connect to a Lightstreamer Server, a LightstreamerClient object has to be created, configured, and instructed to connect to a specified endpoint. A minimal version of the code that creates a LightstreamerClient and connects to the Lightstreamer Server on https://push.lightstreamer.com will look like this:
Otherwise, to send messages in the opposite direction, i.e. from client to server, you only need a single line of code:
The well-know Stock-List Demo with .NET API 5.0.0All the demos of the Microsoft .NET family have been updated with the new APIs, and in particular, I would like to focus on the Stock-List Demo that with the occasion has received a graphic restyling and some enrichment of features. The full source code of the demo can be retrieved from GitHub (https://github.com/Lightstreamer/Lightstreamer-example-StockList-client-dotnet).
The main body of the demo is occupied by a DataGridview which shows the information of the 30 Items all subscribed with a single subscription request. The application code implements a cell highlighting mechanism to highlight cells with a recently updated value.
To propagate any new updates to the market data of a stock from the Lightstrramer Client Library to the DataGridview we use the BeginInvoke to queue update process to the form thread.
At the top right of the form, some controls have been added to manage the client session with the Lightstreamer server and the subscription to the Items displayed in the DataGridview, which allow you to:
- dynamically change the transport over which the client session with the Lightstremer server is based;
- reset the connection with the Lightstreamer server to force a new client session;
- dynamically change the max update frequency allowed for the Items subscribed; varying from unlimited to 1 update every 100 seconds.