134 lines
3.8 KiB
ObjectPascal
134 lines
3.8 KiB
ObjectPascal
|
|
unit MultiChannel_ClientMain;
|
||
|
|
|
||
|
|
interface
|
||
|
|
|
||
|
|
uses
|
||
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||
|
|
StdCtrls, MultiChannelLibrary_Intf, MultiChannel_ClientData, SyncObjs,
|
||
|
|
uROIndyUDPChannel, uROSuperTCPChannel, uROIndyTCPChannel,
|
||
|
|
uROLocalChannel, uRODLLChannel, uRONamedPipeChannel,
|
||
|
|
uROWinMessageChannel, uROClient, uROWinInetHttpChannel, uROBinMessage,
|
||
|
|
uRORemoteService, ExtCtrls;
|
||
|
|
|
||
|
|
type
|
||
|
|
TMultiChannel_ClientMainForm = class(TForm)
|
||
|
|
RemoteService: TRORemoteService;
|
||
|
|
BinMessage: TROBinMessage;
|
||
|
|
WinInetHTTPChannel: TROWinInetHTTPChannel;
|
||
|
|
WinMessageChannel: TROWinMessageChannel;
|
||
|
|
NamedPipeChannel: TRONamedPipeChannel;
|
||
|
|
DLLChannel: TRODLLChannel;
|
||
|
|
LocalChannel: TROLocalChannel;
|
||
|
|
IndyTCPChannel: TROIndyTCPChannel;
|
||
|
|
SuperTcpChannel: TROSuperTcpChannel;
|
||
|
|
IndyUDPChannel: TROIndyUDPChannel;
|
||
|
|
Memo: TMemo;
|
||
|
|
Panel1: TPanel;
|
||
|
|
GetServerTimeButton: TButton;
|
||
|
|
rgConnect: TRadioGroup;
|
||
|
|
procedure GetServerTimeButtonClick(Sender: TObject);
|
||
|
|
procedure FormCreate(Sender: TObject);
|
||
|
|
procedure FormDestroy(Sender: TObject);
|
||
|
|
private
|
||
|
|
CriticalSection: TCriticalSection;
|
||
|
|
function GetMultiChannelService: IMultiChannelService;
|
||
|
|
{ Private declarations }
|
||
|
|
public
|
||
|
|
procedure Log(Astr: string);
|
||
|
|
{ Public declarations }
|
||
|
|
end;
|
||
|
|
|
||
|
|
var
|
||
|
|
MultiChannel_ClientMainForm: TMultiChannel_ClientMainForm;
|
||
|
|
|
||
|
|
implementation
|
||
|
|
|
||
|
|
{$R *.dfm}
|
||
|
|
|
||
|
|
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;
|
||
|
|
{BPDXHTTPServer} 1: begin
|
||
|
|
RemoteService.Channel := WinInetHTTPChannel;
|
||
|
|
WinInetHTTPChannel.TargetURL := Format(atargetUrl, [8098]);
|
||
|
|
end;
|
||
|
|
{SuperTcpServer} 2: begin
|
||
|
|
RemoteService.Channel := SuperTcpChannel;
|
||
|
|
SuperTcpChannel.Host := aHost;
|
||
|
|
end;
|
||
|
|
{IndyTCPServer} 3: begin
|
||
|
|
RemoteService.Channel := IndyTCPChannel;
|
||
|
|
IndyTCPChannel.Host := aHost;
|
||
|
|
IndyTCPChannel.Port := 8090;
|
||
|
|
end;
|
||
|
|
{BPDXTCPServer} 4: begin
|
||
|
|
RemoteService.Channel := IndyTCPChannel;
|
||
|
|
IndyTCPChannel.Host := aHost;
|
||
|
|
IndyTCPChannel.Port := 8089;
|
||
|
|
end;
|
||
|
|
{LocalServer} 5: begin
|
||
|
|
RemoteService.Channel := LocalChannel;
|
||
|
|
end;
|
||
|
|
{IndyUDPServer} 6: begin
|
||
|
|
RemoteService.Channel := IndyUDPChannel;
|
||
|
|
IndyUDPChannel.Host := aHost;
|
||
|
|
IndyUDPChannel.Port := 8090;
|
||
|
|
end;
|
||
|
|
{NamedPipeServer} 7: begin
|
||
|
|
RemoteService.Channel := NamedPipeChannel;
|
||
|
|
end;
|
||
|
|
{WinMessageServer} 8: begin
|
||
|
|
RemoteService.Channel := WinMessageChannel;
|
||
|
|
end;
|
||
|
|
else
|
||
|
|
{DLLChannel}
|
||
|
|
RemoteService.Channel := DLLChannel;
|
||
|
|
end;
|
||
|
|
|
||
|
|
RemoteService.Message := BinMessage;
|
||
|
|
Result := RemoteService as IMultiChannelService;
|
||
|
|
end;
|
||
|
|
|
||
|
|
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;
|
||
|
|
|
||
|
|
procedure TMultiChannel_ClientMainForm.Log(Astr: string);
|
||
|
|
begin
|
||
|
|
CriticalSection.Enter;
|
||
|
|
try
|
||
|
|
Memo.Lines.Add(Astr);
|
||
|
|
finally
|
||
|
|
CriticalSection.Leave;
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TMultiChannel_ClientMainForm.FormCreate(Sender: TObject);
|
||
|
|
begin
|
||
|
|
CriticalSection := TCriticalSection.Create;
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TMultiChannel_ClientMainForm.FormDestroy(Sender: TObject);
|
||
|
|
begin
|
||
|
|
CriticalSection.Free;
|
||
|
|
end;
|
||
|
|
|
||
|
|
end.
|
||
|
|
|