A customer ask if TMS Sparkle and sgcWebSockets can run together, and the answer is yes, there is no problem running sgcWebSockets and TMS Sparkle on the same server. Both can run using HTTP.SYS server, you can run a single HTTP.SYS server and configure endpoints to run with Sparkle and sgcWebSockets without problems. Basically you configure in each package which endpoint will handle.
sgcWebSockets can run in HTTP.SYS server through HTTP API Server:
https://www.esegece.com/help/sgcWebSockets/#t=Components%2FTsgcWebSocketServer_HTTPAPI.htm
Find below 2 samples which show how sgcWebSockets and TMS Sparkle can run on the same HTTP.SYS server.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657program sgcWSServer;{$APPTYPE CONSOLE}{$R *.res}usesSystem.SysUtils,sgcWebSocket, sgcWebSocket_Classes,sgcWebSocket_Server_HTTPAPI;typeTsgcServerClass = classpublicprocedure OnConnectEvent(Connection: TsgcWSConnection);procedure OnMessageEvent(Connection: TsgcWSConnection; const Text: String);end;procedure TsgcServerClass.OnConnectEvent(Connection: TsgcWSConnection);beginConnection.WriteData('Hello From Server.');end;procedure TsgcServerClass.OnMessageEvent(Connection: TsgcWSConnection; constText: String);beginConnection.WriteData(Text);end;varoServer: TsgcWebSocketServer_HTTPAPI;oConnection: TsgcServerClass;begintryoServer := TsgcWebSocketServer_HTTPAPI.Create(nil);oConnection := TsgcServerClass.Create;TryoServer.Bindings.NewBinding('127.0.0.1', 2001, '/ws/');oServer.OnConnect := oConnection.OnConnectEvent;oServer.OnMessage := oConnection.OnMessageEvent;oServer.Active := True;WriteLn('sgcWebSockets Server started at ws://127.0.0.1:2001/ws');while oServer.Active doSleep(10);FinallyoConnection.Free;oServer.Free;End;excepton E: Exception doWriteln(E.ClassName, ': ', E.Message);end;end.
123456789101112131415161718192021222324252627282930313233343536373839program HelloWorldServer;{$APPTYPE CONSOLE}usesSystem.SysUtils,Sparkle.HttpServer.Context,Sparkle.HttpServer.Module,Sparkle.HttpSys.Server;typeTHelloWorldModule = class(THttpServerModule)public procedure ProcessRequest(const C: THttpServerContext); override;end;procedure THelloWorldModule.ProcessRequest(const C: THttpServerContext);beginC.Response.StatusCode := 200;C.Response.ContentType := 'text/plain';C.Response.Close(TEncoding.UTF8.GetBytes('Hello, World!'));end;constServerUrl = 'http://127.0.0.1:2001/rest';varServer: THttpSysServer;beginServer := THttpSysServer.Create;tryServer.AddModule(THelloWorldModule.Create(ServerUrl));Server.Start;WriteLn('Hello World Server started at ' + ServerUrl);WriteLn('Press Enter to stop');ReadLn;finallyServer.Free;end;end.
Follow the instructions below to run the samples:
1. Execute sgcWSServer as Administrator. Will open a WebSocket server, listening on port 2001 and endpoint "/ws"4. Open a http connection to http://127.0.0.1:2001/rest. A simple response from REST server will be shown.
When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.