TsgcWSHTTPWebBrokerBridgeServer

TsgcWSHTTPWebBrokerBridgeServer는 서버 기반으로 TIdHttpWebBrokerBridge를 사용하며, DataSnap, HTTP 및 WebSocket 연결에 단일 서버를 사용하려는 경우 유용합니다.

 

TsgcWSHTTPWebBrokerBridgeServerTsgcWebSocketHTTPServer에서 상속되므로 이 서버를 참조할 수 있습니다.

 

TIdHttpWebBrokerBridgeTsgcWSHTTPWebBrokerBridgeServer로 교체하려면 다음 단계를 따르십시오:

 

1. TsgcWSHTTPWebBrokerBridgeServer의 새 인스턴스를 생성합니다.

 

2. TIdHttpWebBrokerBridge에 대한 모든 호출을 TsgcWSHTTPWebBrokerBridgeServer로 교체하십시오.

 

3. WebSocket 연결을 처리하려면 TsgcWebSocketHTTPServer를 참조하십시오.

 

구성

Datasnap 구성 요소는 Source 폴더에만 위치합니다. 이 객체들은 sgcWebSockets 패키지에 포함되지 않으므로 컴파일된 폴더에서는 찾을 수 없으며, 런타임에 생성해야 합니다.

필요한 파일을 프로젝트에 추가하거나 sgcWebSockets 패키지의 Source 폴더로 경로를 설정하기만 하면 됩니다. 필요한 파일:

 

 

프로젝트가 IdHTTPWebBrokerBridge를 사용하는 경우 sgcIdHTTPWebBrokerBridge로 변경하십시오(이는 Enterprise Edition에만 적용됩니다).

 

Events


FServer := TsgcWSHTTPWebBrokerBridgeServer.Create(Self);
FServer.OnCommandRequest := OnCommandRequestEvent;
FServer.OnCommandGet := OnCommandGetevent;
  
procedure OnCommandRequestEvent(AThread: TIdContext; ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo; var aHandled: Boolean);
begin
  if ARequestInfo.Document = '/test.html' then
    aHandled := True;
end;
 
procedure OnCommandGetevent(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo);
begin
  if ARequestInfo.Document = '/test.html' then
  begin
    AResponseInfo.ResponseNo := 200;
    AResponseInfo.ContentText := 'hello all';
  end;
end;

로드 밸런서

서버가 TsgcWebSocketLoadBalancerServer 뒤에 있는 경우 CORS와 관련된 문제가 발생할 수 있습니다. 이러한 문제를 방지하려면 다음 코드를 사용하십시오

 


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;