标签:test lis send abc ber ant port host 发布
前几天,Delphi 10.3.2 正式发布,这个小版本升级却增加了一个非常大的平台支持,增加了
macos 64位的支持,今天做一个macOS 64位的kbmmw应用,让kbmmw 服务器的应用更广泛。
当然了,你需要先根据要求,设置好相关的·macos64 的开发环境。
首先我们新建一个FMX 应用。
设置对应的参数
procedure TForm2.Button1Click(Sender: TObject); begin kbmmwserver1.AutoRegisterServices; kbmmwserver1.Active:=true; end;
平台上添加mac os64
新建一个kbmmw 服务。
服务名设为mactest,生成一个服务,并修改代码如下:
type [kbmMW_Service(‘name:mactest, flags:[listed]‘)] [kbmMW_Rest(‘path:/mactest‘)] // Access to the service can be limited using the [kbmMW_Auth..] attribute. // [kbmMW_Auth(‘role:[SomeRole,SomeOtherRole], grant:true‘)] TkbmMWCustomHTTPSmartService1 = class(TkbmMWCustomHTTPSmartService) private { Private declarations } protected { Protected declarations } public { Public declarations } // HelloWorld function callable from both a regular client, // due to the optional [kbmMW_Method] attribute, // and from a REST client due to the optional [kbmMW_Rest] attribute. // The access path to the function from a REST client (like a browser)+ // is in this case relative to the services path. // In this example: http://.../mactest/helloworld // Access to the function can be limited using the [kbmMW_Auth..] attribute. // [kbmMW_Auth(‘role:[SomeRole,SomeOtherRole], grant:true‘)] [kbmMW_Rest(‘method:get, path:helloworld‘)] [kbmMW_Method] function HelloWorld:string; [kbmMW_Method] function version:string; [kbmMW_Method] function EchoString(const AString:string):string; [kbmMW_Method] function AddNumbers(const AValue1,AValue2:integer; [kbmMW_Arg(mwatRemoteLocation)] const ARemoteLocation:string ):integer ; end; implementation {%CLASSGROUP ‘System.Classes.TPersistent‘} uses kbmMWExceptions, mainp; {$R *.dfm} // Service definitions. //--------------------- function TkbmMWCustomHTTPSmartService1.AddNumbers(const AValue1, AValue2: integer; const ARemoteLocation: string): integer; begin Result:=AValue1+AValue2; end; function TkbmMWCustomHTTPSmartService1.EchoString( const AString: string): string; begin Result:=AString; end; function TkbmMWCustomHTTPSmartService1.HelloWorld:string; begin Result:=‘Hello world‘; end; function TkbmMWCustomHTTPSmartService1.version: string; begin result:=‘kbmmw server for macos 64‘; end; initialization TkbmMWRTTI.EnableRTTI(TkbmMWCustomHTTPSmartService1); end.
服务端做好了
我们可以运行了。
现在做一个简单客户端
设置对应的代码
procedure TForm1.Button1Click(Sender: TObject); var c:IkbmMWSmartClient; s:string; begin Transport.Host:=eIP.Text; // Get a client which establishes connection over the given transport // to the given service which is set to be default for this client. c:=TkbmMWSmartRemoteClientFactory.GetClient(Transport,‘MACTEST‘); s:=c.Service. helloworld ; memo1.Lines.Add(s); s:=c.Service.EchoString(‘abc‘); memo1.Lines.Add(s); s:=c.Service.version; memo1.Lines.Add(s); s:=c.Service.AddNumbers(34,7); memo1.Lines.Add(s); end;
运行客户端
正确运行。
基本上比较顺利。
标签:test lis send abc ber ant port host 发布
原文地址:https://www.cnblogs.com/xalion/p/11217300.html