TsgcWSServer_HTTPAPI_WebBrokerBridge use TsgcWebSocketServer_HTTPAPI with HTTP/2 protocol enabled as server base and is useful if you want to use a single server for DataSnap, HTTP/2 and WebSocket connections.
TsgcWSServer_HTTPAPI_WebBrokerBridge inherits from TsgcWebSocketServer_HTTPAPI, so you can refer to this server.
Follow next steps to replace TIdHttpWebBrokerBridge for TsgcWSServer_HTTPAPI_WebBrokerBridge:
1. Create a new instance of TsgcWSServer_HTTPAPI_WebBrokerBridge.
2. Replace all calls to TIdHttpWebBrokerBridge for TsgcWSServer_HTTPAPI_WebBrokerBridge.
3. To Handle WebSocket connections just refer to TsgcWSServer_HTTPAPI_WebBrokerBridge.
The Datasnap components are only located in Source folder, you won't find in the compiled folders because these objects are not included in sgcWebSockets package, so you must create in runtime.
Just add the required files to your project or set your path to the Source folder of sgcWebSockets package. Files required:
If the project makes uses of IdHTTPWebBrokerBridge change to sgcIdHTTPWebBrokerBridge (this only applies for Enterprise Edition).
FServer := TsgcWSServer_HTTPAPI_WebBrokerBridge.Create(Self);
FServer.OnCommandRequest := OnCommandRequestEvent;
FServer.OnMessage := OnWebSocketMessage;
procedure OnCommandRequestEvent(aConnection : TsgcWSConnection_HTTPAPI;
const aRequestInfo: THttpServerRequest; var aResponseInfo: THttpServerResponse; var aHandled: Boolean);
begin
if ARequestInfo.Document = '/test.html' then
begin
AResponseInfo.ResponseNo := 200;
AResponseInfo.ContentText := '... body ...';
aHandled := True;
end;
end;
procedure OnWebSocketMessage(aConnection: TsgcWSConnection; const aText: string);
begin
aConnection.WriteData(aText);
end;