sgcWebSockets · Technical Document

DataSnap — WebBroker Bridge (WebSockets)

TsgcWSHTTPWebBrokerBridgeServer — pure-Delphi WebBroker / DataSnap host with WebSocket transport on top of TsgcWebSocketHTTPServer.

Overview

TsgcWSHTTPWebBrokerBridgeServer make use of TIdHttpWebBrokerBridge as server base and is useful if you want to use a single server for DataSnap, HTTP and WebSocket connections.

At a glance

Component class
TsgcWSHTTPWebBrokerBridgeServer
Standards / spec
WebSocket Protocol — RFC 6455
Transports
TCP, TLS
Platforms
Windows, macOS, Linux, iOS, Android
Frameworks
VCL, FireMonkey, Lazarus / FPC
Edition
Standard / Professional / Enterprise

Features

Technical specification

Standards & specsWebSocket Protocol — RFC 6455
Component classTsgcWSHTTPWebBrokerBridgeServer (unit sgcWebSocket_HTTP_WebBrokerBridge)
FrameworksVCL, FireMonkey, Lazarus / FPC
PlatformsWindows, macOS, Linux, iOS, Android

Main properties

The principal published / public properties used to configure and drive the component. Consult the online help for the full list.

DefaultPortPublished or public property used to configure or query the component.
HTTPWebBrokerBridgePublished or public property used to configure or query the component.
NotifyEventsPublished or public property used to configure or query the component.
OnCommandRequestPublished or public property used to configure or query the component.
OnBeforeCommandPublished or public property used to configure or query the component.
OnCommandGetPublished or public property used to configure or query the component.
OnCommandOtherPublished or public property used to configure or query the component.
OnCreateSessionPublished or public property used to configure or query the component.
OnInvalidSessionPublished or public property used to configure or query the component.
OnSessionEndPublished or public property used to configure or query the component.

Main methods

The principal public methods exposed by the component.

PushPromiseAddPreLoadLinks()Public procedure exposed by the component.
PushPromiseRemovePreLoadLinks()Public procedure exposed by the component.

Quick Start

Drop the component on a form, configure the properties below and activate it. The snippet that follows shows the typical Load Balancer configuration sourced from the online help.

About this scenario. If the server is behind the TsgcWebSocketLoadBalancerServer, you may have issues with CORS, to avoid these issues, use the following code

Delphi (VCL / FireMonkey)

procedure TWebModule1.WebModuleBeforeDispatch(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
 Response.SetCustomHeader('Access-Control-Allow-Origin','*');    
 if Trim(Request.GetFieldByName('Access-Control-Request-Headers')) <> '' then
 begin
  Response.SetCustomHeader('Access-Control-Allow-Headers', Request.GetFieldByName('Access-Control-Request-Headers'));    
  Handled := True;
 end;
 if FServerFunctionInvokerAction <> nil then
  FServerFunctionInvokerAction.Enabled := AllowServerFunctionInvoker;
end;

C++ Builder

void __fastcall TWebModule1::WebModuleBeforeDispatch(TObject *Sender, TWebRequest *Request, TWebResponse *Response, bool &Handled)
{
  Response->SetCustomHeader("Access-Control-Allow-Origin", "*");
  if (Trim(Request->GetFieldByName("Access-Control-Request-Headers")) != "")
  {
    Response->SetCustomHeader("Access-Control-Allow-Headers", Request->GetFieldByName("Access-Control-Request-Headers"));
    Handled = true;
  }
  if (FServerFunctionInvokerAction != nullptr)
  {
    FServerFunctionInvokerAction->Enabled = AllowServerFunctionInvoker;
  }
}

.NET (C#)

void WebModuleBeforeDispatch(object Sender, TWebRequest Request, TWebResponse Response, ref bool Handled)
{
  Response.SetCustomHeader("Access-Control-Allow-Origin", "*");
  if (Request.GetFieldByName("Access-Control-Request-Headers").Trim() != "")
  {
    Response.SetCustomHeader("Access-Control-Allow-Headers", Request.GetFieldByName("Access-Control-Request-Headers"));
    Handled = true;
  }
  if (FServerFunctionInvokerAction != null)
  {
    FServerFunctionInvokerAction.Enabled = AllowServerFunctionInvoker;
  }
}

Sources used to build this document

Every external claim links back to a primary source. The online-help references decode the canonical deep-link the company maintains for this component.

Document scope. This document covers the publicly-documented surface of the DataSnap — WebBroker Bridge (WebSockets) component shipped with sgcWebSockets. For full property, method and event reference consult the online help linked above.