Build A Robust, Scalable, Real-time Websocket Client & Server

HTTP is one of, if not the most, widely used client server protocols. It has been serving up our favorite webpages, blogs and even this site for many years through its life time carried on the shoulders of the reliable TCP. But technology is evolving, and over time it has become clear there are some limitations with HTTP. The first thing is that HTTP is unidirectional. With HTTP, the client starts the request first and the server responds. So for every resource the client is the one who polling for the resource. Added to that, HTTP expects that each interaction has a timeout before it’s assumed that the server is not responding.

What are the solutions for the HTTP limitations?

Long-polling serves as a solution to the limitations of HTTP based technology. In this case, the client sends request with a long timeout. This allows the server lots of time to reply without the connection expiring due to inactivity or an inability to respond. This was a solution for up to a certain level, but this is very resource hogging. It’s because the server resources are reserved and dedicated to the client during the long polling.

Are Websockets a better solution for HTTP limitations?

Yes, Websockets are a better solution to help mitigate some of the HTTP timeout limitation. Websockets can use HTTP to initialize the connection and, using the same TCP connection, upgrade to a websocket. With Websockets, we have a persistent bi-directional connection which is less resource intensive than long polling. Both the server and client can push messages any time. Today most of the web browsers support the Websocket protocol. Also the fifth version of HTML (HTML5) includes support for websockets. So in general, Websockets allow you to build real time client server applications.

How do I implement websocket applications with Delphi or C++ builder?

IPWorks has a complete solution to implement both Websocket server and client. It has following components:

TipeCertMgr: This component used to store certificates.

TipeWebSocketServer: This is the server component which accepts websocket client requests.

TipeWebSocketClient: This is the client component which can connect to a websocket server and send or receive data.

TipeWebSocketProxy: This component will accept Websocket connections for a websocket server and instead redirect to another server.

By using these components you can develop a complete Websocket client and server application. These components are native and doesn’t need any external libraries. Also the components are optimized and work efficiently. It’s very secure with the WebSocket Secure 256-bit encryption. These components are thread safe. As an added bonus they also have a good documentation to get started:

https://cdn.nsoftware.com/help/IWF/dlp/

How do I use IPWorks WebSockets?

IPWorks provide a free trial version of their WebSocket component pack for both Delphi and C++ builder. You can evaluate those components in your application. You can acquire the components from this link:

https://www.nsoftware.com/ipworks/ws/download.aspx

You can also use the GetIt package manager to search for an find trial versions of IPWorks:

https://getitnow.embarcadero.com

IPWorks WebSockets component installer comes with a demo application which works out of the box. It has a nice little Websocket echo server and a client application to connect to the websocket server.

Here is a Delphi WebSocket Server Demo

IPWorks WebSockets Server

Here is a Delphi WebSocket Client Demo

IPWorks WebSockets Client

How do I create a demo WebSocket server In RAD Studio Delphi?

To create a Websocket server using IPWorks Websocket components, just drag and drop a TipeWebSocketServer component to a form. You have to setup basic parameters like the port going to use and weather this is a SSL server or not. If it’s a SSL server, you have to add a TipeCertMgr component and assign certificate details there. Once you set the all mandatory parameters, you can set “Listening” property to true and it will start the server and accept client requests through the port. Sever component has many events you can handle. Some of them are:

OnConnected: Triggers when new client connected.

OnDataIn: When receive data from a client

OnDisconnected: Triggers when client is disconnected.

OnError: This will call with a connection ID, error code and an error description for an error.

How do I create a demo WebSocket client In RAD Studio Delphi?

To create a Websocket client, you can use the TipeWebSocketClient component. Just place the component on a form, set some mandatory parameters and you have the working client. Then you can call the procedure “Connect(ws://SERVER:PORT)” to connect to the server. Once your work is done, you can disconnect from the server by calling “Disconnect” procedure. The client also have similar event like the server.

OnConnected: Triggers when connected to the server.

OnDataIn: When receive data from the server.

OnDisconnected: Disconnected from the server.

OnError: This will call with an error code and an error description for an error.

IPWorks WebSockets is one of the best solutions for developing robust, advanced, yet developer-friendly Websocket client server applications.

close

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition