Multi-node Clustering (TsgcWSCluster) — sgcWebSockets | eSeGeCe

Multi-node Clustering

TsgcWSCluster — scale your sgcWebSockets servers across multiple nodes. A publish or Presence event on any node reaches subscribers connected to every other node, through a zero-infrastructure mesh backplane or a Redis Pub/Sub backplane. Your existing Publish, channel and Presence code stays unchanged.

TsgcWSCluster

Put two or more WebSocket servers behind a load balancer and a message published on one node still reaches subscribers connected to the others. Drop the component next to your server, point the nodes at each other, and channels, broadcasts and Presence work cluster-wide.

Component class

TsgcWSCluster

Backplane

Mesh (zero-infrastructure) or Redis Pub/Sub

Platforms

Delphi 7–13 (Win32/Win64, Linux64, macOS, Android, iOS) and .NET

Edition

Enterprise

Drop the component, point the nodes at each other, go

Attach the sgc protocol to the cluster and start it. A client on one node can Publish to a channel and clients on the other nodes receive it, with no sticky sessions.

uses
  sgcWebSocket, sgcWebSocket_Protocols, sgcWebSocket_Cluster;

var
  Server: TsgcWebSocketServer;
  Protocol: TsgcWSPServer_sgc;
  Cluster: TsgcWSCluster;
begin
  Server := TsgcWebSocketServer.Create(nil);
  Server.Port := 8080;

  Protocol := TsgcWSPServer_sgc.Create(nil);
  Protocol.Server := Server;

  Cluster := TsgcWSCluster.Create(nil);
  Cluster.EngineType  := clusterMesh;                // zero-infrastructure backplane
  Cluster.ClusterPort := 5410;                       // this node's mesh listener
  Cluster.Peers.Add('192.168.1.101:5410');          // the other nodes
  Cluster.Peers.Add('192.168.1.102:5410');
  Cluster.Attach(Protocol);                          // cluster this protocol's pub/sub
  Cluster.Start;

  Server.Active := True;
end;
var server = new TsgcWSServer { Port = 8080 };
var protocol = new TsgcWSPServer_sgc { Server = server };

var cluster = new TsgcWSCluster {
    EngineType  = ClusterEngineType.Mesh,   // zero-infrastructure backplane
    ClusterPort = 5414,
    Protocol    = protocol
};
cluster.Peers.Add("192.168.1.101:5414");
cluster.Peers.Add("192.168.1.102:5414");
cluster.Start();

server.Active = true;

What's inside

Two backplane engines, drop-in Attach, and cluster-wide Presence — pulled from the component reference.

Backplane engines

Published property EngineType: clusterMesh (no external infrastructure) or clusterRedis (Redis Pub/Sub).

Mesh

Properties: ClusterPort, Peers. Each node listens and connects directly to its peers — nothing extra to install.

Redis

Properties: RedisHost, RedisPort, RedisChannel for larger deployments.

Attach

Methods: Attach, Detach, Start, Stop. Cluster the sgc protocol and Presence with one call each.

Cluster-wide Presence

The member roster becomes the union across all nodes; a node that drops has its members purged, so no ghost members.

Health

Property Ready, ConnectedPeerCount and events OnPeerConnected, OnPeerDisconnected, OnClusterMessage.

Specifications & references

Authoritative sources for the backplane this component builds on.

Documentation & Demos

Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.

Demo Project — 02.WebSocket_Protocols\14.MultiNode_Clustering Ready-to-run two-node example. Ships inside the sgcWebSockets package — download the trial below.
Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.

Scale Your WebSocket Servers Across Nodes

Download the free trial and cluster your sgcWebSockets deployment with a mesh or Redis backplane.