Multi Channel sample (Delphi)

Overview

This sample provides an introduction to using the Delphi edition of the Remoting SDK product. It shows how to use different channels to connect to the server application. The following channels and servers are included:

Getting Started

  • Compile all projects.
  • Launch the server (via the menu command: Tools -> Remoting SDK -> Launch Server Executable).
  • Activate the server(s) you require.
  • Ensure that MultiChannel_Client is the selected project and run it.
  • Choose a server to use and see how it works by clicking the GetServerTime button.

Examine the Code

See the code that changes the selected channel/server in the MultiChannel_ClientMain.pas file. Notice how each channel is configured at runtime.

function TMultiChannel_ClientMainForm.GetMultiChannelService: IMultiChannelService;
const
  atargetUrl = 'http://localhost:%d/BIN';
  aHost = '127.0.0.1';
begin
  case rgConnect.ItemIndex of
    {IndyHTTPServer} 0: begin
        RemoteService.Channel := WinInetHTTPChannel;
        WinInetHTTPChannel.TargetURL := Format(atargetUrl, [8099]);
      end;
    {SuperTcpServer} 1: begin
        RemoteService.Channel := SuperTcpChannel;
        SuperTcpChannel.Host := aHost;
      end;
    {IndyTCPServer} 2: begin
        RemoteService.Channel := IndyTCPChannel;
        IndyTCPChannel.Host := aHost;
        IndyTCPChannel.Port := 8090;
      end;
    {LocalServer} 3: begin
        RemoteService.Channel := LocalChannel;
      end;
    {IndyUDPServer} 4: begin
        RemoteService.Channel := IndyUDPChannel;
        IndyUDPChannel.Host := aHost;
        IndyUDPChannel.Port := 8090;
      end;
    {NamedPipeServer} 5: begin
        RemoteService.Channel := NamedPipeChannel;
      end;
    {WinMessageServer} 6: begin
        RemoteService.Channel := WinMessageChannel;
      end;
    {SuperHTTPServer} 7: begin
        RemoteService.Channel := IndySuperHttpChannel;
        IndySuperHttpChannel.TargetURL := Format(atargetUrl, [8094]);
      end;
  else
    {DLLChannel}
    RemoteService.Channel := DLLChannel;
  end;

  RemoteService.Message := BinMessage;
  Result := RemoteService as IMultiChannelService;
end;
  • As for the service call code, it is quite simple and uses the routine above:
procedure TMultiChannel_ClientMainForm.GetServerTimeButtonClick(
  Sender: TObject);
var
  srv: IMultiChannelService;
begin
  srv := GetMultiChannelService;
  Log('use ' + RemoteService.Channel.Name);
  Log('GetServerTime');
  Log('-------------');
  Log('Receiving:'#9 + DateTimeToStr(srv.GetServerTime));
  Log('');
end;