TsgcWebSocketServer is part of the sgcWebSockets suite and provides a high-level component for creating WebSocket servers in C++Builder. This guide walks through creating a minimal server that automatically replies to incoming messages.
Create the VCL project
- Open C++Builder and create a new VCL Forms Application.
- Drop a
TsgcWebSocketServercomponent on the form (namedsgcWSServer1by default). - Optionally add a
TMemo(MemoLog) to display activity.
Configure the server
Set up the server in the form's OnCreate handler:
Respond to incoming messages
Handle the OnMessage event to echo the received text back to the client:
WriteData transmits the response only to the specific connection, whereas Broadcast sends the message to every connected client.
Run the server
Compile and run the application. Any WebSocket client that connects to ws://<your-host>:9001/ will receive a response prefixed with "Server received:" for every message it sends.