Websockets Harness Real-Time Power In Your Delphi Apps

Are you using websockets in your applications yet? Do you need to know what websockets can do for your apps? Read on to get up to speed on everything you need to know about using websockets with Delphi along with a run-down on some of the available component sets which take all the hard work out of making the magic happen.

What are websockets?

There are two sides to a websocket implementation – the client side and the server side. At the most basic level a websocket server is an application which listens for TCP traffic. The websockets clients are one or more applications or even web pages which connect to the websocket server via a “handshake” request and, if successful, a continuous connection is established between the server and the client.

Are websockets just a special type of HTML?

The short answer to that question is no, websockets use the TCP communication protocol – not the much more heavyweight HTTP. The websockets server is not a web server, although it can be implemented on one. The websockets TCP traffic, the data sent back and forth between the client and server, is not the familiar “200 OK” and “HTTP/2.0 a bunch of HTML” type text data. The websockets protocol is very lightweight and as a result, very fast.

Websockets are also designed to be used in situations where there are prolonged and ‘constantly-on’ connections to the server by multiple clients. Compare that to HTML where the interaction is typically client makes a page request, the web server sends back its response and that’s end of interaction until the next web resource request. Websockets are more like a ‘push’ technology where the server can send updates without being asked. This push ability is more similar to the notifications on your mobile phone.

Are websockets secure?

The websocket protocol provides for both non-secure and secure connections. The secure protocol uses TLS/SSL.

Why would I want to use websockets in my app?

Websockets are really useful for applications which need to update small amounts of data frequently and on a schedule which is not predictable. You can use websockets to provide a highly efficient way of communicating that data without the overhead of things like REST which relies on HTML and therefore has all the added baggage of HTML request/response codes, headers and MIME types. Your applications cut out all that extra noise using websockets while providing a near real-time response without needing to implement things like the server or client polling for any requests or updates.

This makes your app super-responsive and lightweight.

What sort of applications can I write?

The most common example you see given for websockets is in real-time “chat” programs which emulate popular apps like Slack, Discourse and Messenger. There are a whole host of other uses too:

  • “Feed” type usage – like a Twitter tweet feed or an “as it happens” time and status update print-out from something like a temperature monitoring hardware control.
  • Two-way updates between two client applications. For example, two users are both updating a shared resource like a set of notes or different parts of a patient record. Using websockets you could implement an update mechanism where both users could see the other’s changes in near-real time rather than having to hit a refresh or reload button.
  • Real time location monitoring. By using websockets in your Delphi app you could have an interactive map which updates the display in real-time when it gets changed, rather than when you ‘poll’ the server.
  • In/Out board. Websockets would allow you to write a client/server application which showed a live, real-time and constantly up-to-date view of employee’s in/out or available/unavailable status in the office without having to constantly run database queries to get that data or poll the server for the information on a timing loop.

What websocket libraries are available for Delphi?

The “RAD” in RAD Studio Delphi is, of course, all about Rapid Application Development which means we use someone else’s hard work to make our lives easier. Luckily there is a solid stack of excellent Delphi websocket components available. This is a list of some of the more popular websocket component libraries available for Delphi. There are plenty of others so add a comment below if I’ve missed any you think should be on the list.

Commercial/paid websockets libraries for Delphi

N Software websockets Delphi components

IPWorks from /n Software have a specific Delphi websocket library.

A free trial of their library is available on GetIt https://getitnow.embarcadero.com/trial-ipworks-websockets-2020-c-builder-edition/

IPWorks is licensed per platform and includes free upgrades for a year.

Note that you would need a license for each platform if you buy it individually although /n Software do a “red carpet subscription” for just over twice the price of a single subscription and this gives you access to all editions and all platforms on multiple machines.

Devart’s Secure Bridge contains a websocket client for Delphi and it’s easy to use. They have a 60 day free trial after which the library requires a payment that comes with 1 year of technical support and updates. They do not have a websocket server component.

You can read more about Secure Bridge and the Delphi websocket client it contains here: https://www.devart.com/sbridge/delphi-websocket-client-component.html

Devart SecureBridge websockets for Delphi
ESEGECE websockets Delphi components

ESEGECE Websockets is a really great library which provides components that implement both client and, in the Enterprise version, server-side websockets for Delphi.

The components work on all platforms including Windows, macOS, iOS and Android as well as Linux 64 bit.

There is a trial available after which you pay a single fee which includes one year of support.

You can get ESEGECE websockets from https://www.esegece.com/websocket

Web-based components for Delphi

TMS WEB Core contains websockets for Delphi

If you are looking to write web applications with Delphi, TMS Software have websockets components available for use in TMS WEB Core applications. TMS WEB Core allows you to write fully interactive web applications using Delphi code.

There is a trial available of TMS WEB Core and you can then either buy the product individually or as part of their TMS All Access package which contains every component and library TMS sell.

You can read more about using websockets in your Delphi web applications here https://www.tmssoftware.com/site/blog.asp?post=460 and get more information about TMS WEB Core itself here: https://www.tmssoftware.com/site/tmswebcoreintro.asp

Free websockets libraries for Delphi

ICS Internet Component Suite has completely free websockets Delphi components

ICS Internet Component Suite is a free component suite from OverByte

ICS contains free Delphi websocket components which allow you to write apps which implement websocket clients and websocket servers. The ICS library is available only as source code and it works on all versions of Delphi from 7 right up to the latest versions. ICS also works cross-platform for macOS using Firemonkey.

The websockets are only a small part of ICS and it includes code for other protocols such as FTP, SMTP, HTTP and also supports SSL and TLS via OpenSSL. You can download ICS Internet Component Suite via GetIt: https://getitnow.embarcadero.com/ics-for-fmx-and-vcl/ or go directly to the OverByte download area to get the very latest version: http://wiki.overbyte.eu/wiki/index.php/ICS_Download

What’s next for using websockets with Delphi?

My next blog post here on The Embarcadero Blog will be a full hands-on tutorial of using websockets in a Delphi application. We’re actually going to implement both a websockets server in Delphi and a Delphi websockets client too.

So, are you ready to use real-time streaming websockets in your Delphi programs?