Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++CodeDelphiRAD Studio

Learn to Use Powerful SGC WebSockets WebRTC in C++ Builder

pexels andrea piacquadio 3756679

Do you want to learn what Websockets? What is WebRTC? How can we Install and use SGC Websockets WebRTC? Can we use web sockets compatible with HTTP proxies? How do I find easy-to-use WebRTC components for C++ IDE? The present post answers these questions as below. We have other articles on the blog showing some of the many uses of the Websocket protocol – you can find them by clicking here.

What are WebSockets?

WebSocket is a communications protocol, was standardized by the IETF as RFC 6455 in 2011, and the WebSocket API in Web IDL is being standardized by the W3C. The WebSocket protocol uses a single TCP connection to provide full-duplex communication channels.

WebSocket is compatible with HTTP because of being designed to work over HTTP ports 443 and 80 as well as to support HTTP proxies and intermediaries. The WebSocket handshake uses the HTTP Upgrade header[1] to change from the HTTP protocol to the WebSocket protocol, to achieve this compatibility. That means in a Communication with Websockets, the communication begins with an HTTP request, then upgrades to Websockets protocol using the TCP protocol connection for communication.

What is WebRTC?

WebRTC (Web Real-Time Communication) is a free, open-source WebSockets communication protocol that provides real-time communication (RTC) between web browsers and mobile applications via simple application programming interfaces (APIs). WebRTC allows direct peer-to-peer communication, eliminating the need to install plugins or download native apps with audio and video communications.

How to use WebRTC components for C++ Builder?

Sergio Gómez, is an individual developer specializing with Embarcadero tools since 1999. In 2012, he started the eSeGeCe website to provide components for Delphi, CBuilder, and .NET developers. Detailed information about WebRTC can be found on their ESEGECE web page here

Installation

  1. Download sgc WebRTC from their official eSeGeCe web page here

2. Unpack the zipped file to a folder and got to “sgcWebSockets_cbuilder_C10_4Packages” folder

3. There is a dclsgcWebSocketsC10_4.cbproj which is a package that has sgc WebSockets components. If you have RAD Studio 10.4.x double click on it or open it via RAD Studio

4. In Projects windows on the right side, right click to dclsgcWebSocketsC10_4.bpl and select Build, and again select Install as below,

Learn to Use Powerful SGC WebSockets WebRTC in C++ Builder installing the components

Now you can see Tsgc… WebSockets classes in your Palette.

Learn to Use Powerful SGC WebSockets WebRTC in C++ Builder the list of sgcComponents

In RAD Studio, select Tools->Options menu and then go to Language->C++->Paths and Directories section,

Learn to Use Powerful SGC WebSockets WebRTC in C++ Builder settings the paths and directiones

Here, be sure that Windows 32-bit is selected and click the ellipsis “…” button at the right side of System Include path and add libC10_4/win32 or libD10_4/win32 folder to these paths.

Also, set the Selected Platform to Windows 64-bit and be sure that Windows 64-bit is selected, Click the … button at the right side of System Include path and add libC10_4/win64 or libD10_4/win64 folder to these paths.

If you have a problem adding these please watch their official video in there download page here

C++ Builder example of how to use WebSockets

  1. Create a new VCL C++ Application and save all project files units into a new folder.
  2. From Tools palette add 2 buttons (name ‘Connect‘ and ‘Disconnect‘) and Memo1 as an output
  3. Add a sgcWebSocketServer, sgcWebSocketClient and sgcWebRTCServer,
Learn to Use Powerful SGC WebSockets WebRTC in C++ Builder example screen

4. Double click to Connect and Disconnect buttons to create their OnClick events. You can use F12 to switch form and code display.
5. Select sgcWebSocketServer1, in Object Inspector, goto it’s events double click to OnConnect and OnDisconnect events
6. Now we can Activate the Server and, modify Connect and Discconect by these buttons and we can msg this into our Memo1 component. Modify your codes as below.

7. Now you can run your application by pressing F9

Note that when you run, to communicate with Sockets you must allow public networks as below,

Learn to Use Powerful SGC WebSockets WebRTC in C++ Builder Windows firewall message

8. If all is fine, from this point, now you can use thir WebRTC component, drag sgcWebRTCServer and be sure it’s Server is set to sgcWebSocketServer1. WebRTC protocol provides real-time communication (RTC) between web browsers and mobile applications via simple application programming interfaces (APIs). WebRTC allows direct peer-to-peer communication, eliminating the need to install plugins or download native apps with audio and video communications. You can check Subscription events by using the events of this component. You can add a Broker by using a sgc Broker component. They have a very good example about it. Please follow their example demos for more details.

As you see it is very easy to do WebRTC connections with C++ Builder or Delphi and with sgcWebSockets components, You can download sgc WebRTC from their official eSeGeCe web page here.

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, Mac-OS, iOS & Android operating systems. There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from from this link. For professional developers, we have Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.

Final Notes

In my trial version tests of sgcWebSockets with the latest RADS 10.4.2 , I see that their package has some conflicts with its other packages If you try to install both C++ Builder and Delphi packages to RADS this time there is a error. That means you can not install both packages to same RAD Studio.

Learn to Use Powerful SGC WebSockets WebRTC in C++ Builder error message

This package conflict error might be a problem if you develop in both C++ Builder / Delphi. I don’t know if it supports both Delphi & C++, They should fix this to support both language. I might have a wrong installation way to install but they should make them friendly.


RAD Studio is a full-featured IDE which allows you to create applications which can work on Windows, Linux, macOS, iOS and Android. Why not download a free trial today?


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

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES