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 […]
