博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用delphi-cross-socket 开发kbmmw smart http service
阅读量:6180 次
发布时间:2019-06-21

本文共 5581 字,大约阅读时间需要 18 分钟。

前几天我说了使用delphi-cross-socket 扩展kbmmw 的跨平台支持,今天我说一下使用

kbmMWCrossScoketHttpServerTransport 在linux 下支持 kbmmw 的samrt HTTP service.

本例子基于以前的 。

我们首先在dm 里面放置两个控件。

加入我们的smart http service.

连接linux 运行.

在浏览器里面访问。

 

 

 在linux 里面查看进程

 

大家可以看见这个后台进程。

ok, 跨平台就这么任性。

相关代码

program Project2;{
$APPTYPE CONSOLE}{
$R *.res}uses Posix.Unistd, Posix.SysTypes, System.SysUtils, dmp in 'dmp.pas' {
dmf: TDataModule}, httpservice in 'httpservice.pas' {
kbmMWCustomHTTPSmartService1: TkbmMWCustomHTTPSmartService};procedure daemon;begin dmf:=Tdmf.Create(nil); dmf.kbmmwserver1.AutoRegisterServices; dmf.kbmMWServer1.Active:=True; writeln('service started'); try repeat sleep(10 * 1000); until False; finally dmf.Free; end;end;var pid: pid_t;begin pid := fork; if pid = 0 then begin writeln('starting service'); daemon; end;end.

 

unit httpservice;// =========================================================================// kbmMW - An advanced and extendable middleware framework.// by Components4Developers (http://www.components4developers.com)//// Service generated by kbmMW service wizard.//// INSTRUCTIONS FOR REGISTRATION/USAGE// -----------------------------------// Please update the uses clause of the datamodule/form the TkbmMWServer is placed on by adding services unit name // to it. Eg.// //     uses ...,kbmMWServer,YourServiceUnitName;// // Somewhere in your application, make sure to register the serviceclass to the TkbmMWServer instance.// This can be done by registering the traditional way, or by using auto registration.// // Traditional registration// ------------------------// var//    sd:TkbmMWCustomServiceDefinition;// ..//    sd:=kbmMWServer1.RegisterService(yourserviceclassname,false);// // Set the last parameter to true if this is the default service.// // // Auto registration// -----------------// Make sure that your service class is tagged with the [kbmMW_Service] attribute.// Then auto register all tagged services:// ..//    kbmMWServer1.AutoRegisterServices;// // -----------------------------------------------// // SPECIFIC HTTP SERVICE REGISTRATION INSTRUCTIONS// -----------------------------------------------// Cast the returned service definition object (sd) to a TkbmMWHTTPServiceDefinition. eg:// // var//    httpsd:TkbmMWHTTPServiceDefinition;// ..//    httpsd:=TkbmMWHTTPServiceDefinition(sd)//    httpsd.RootPath[mwhfcHTML]:='/';//    httpsd.RootPath[mwhfcImage]:='/images';//    httpsd.RootPath[mwhfcJavascript]:='/js';//    httpsd.RootPath[mwhfcStyleSheet]:='.';//    httpsd.RootPath[mwhfcOther]:='.';// -----------------------------------------------{
$I kbmMW.inc}interfaceuses SysUtils,{
$ifdef LEVEL6} Variants,{
$else} Forms,{
$endif} Classes, kbmMWSecurity, kbmMWServer, kbmMWServiceUtils, kbmMWGlobal, kbmMWCustomHTTPSmartService ,kbmMWHTTPUtils, kbmMWSmartServiceUtils, kbmMWRTTI;type [kbmMW_Service('name:xalionrest, flags:[listed]')] [kbmMW_Rest('path:/xalionrest')] // Access to the service can be limited using the [kbmMW_Auth..] attribute. // [kbmMW_Auth('role:[SomeRole,SomeOtherRole], grant:true')] //[kbmMW_HTTP('accept:[get], root:[media:"webfiles", html:"webfiles"]')] 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://.../xalionhttp/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_Rest('method:get, path:version')] [kbmMW_Method] function version:string; [kbmMW_Method('EchoString')] // 回应输入的串 [kbmMW_Rest('method:get, path: ["echostring/{AString}","myechostring/{AString}" ]')] [kbmMW_Auth('role:[SomeRole,SomeOtherRole], grant:true')] function EchoString([kbmMW_Rest('value: "{AString}"')] const AString:string):string; [kbmMW_Method] [kbmMW_Rest('method:get, path: "cal/addnumbers"')] function AddNumbers([kbmMW_Rest('value: "$arg1", required: true')] const AValue1:integer; [kbmMW_Rest('value: "$arg2", required: true')] const AValue2:integer; [kbmMW_Arg(mwatRemoteLocation)] const ARemoteLocation:string):string; [kbmMW_Rest('method:post, path:postdata')] [kbmMW_Method] function postdata:string; end;implementation{
%CLASSGROUP 'System.Classes.TPersistent'}uses kbmMWExceptions;{
$R *.dfm}// Service definitions.//---------------------function TkbmMWCustomHTTPSmartService1.version: string;begin Result:='{"result":"'+self.Server.Version+':'+TOSversion.ToString +'"}';end;function TkbmMWCustomHTTPSmartService1.AddNumbers(const AValue1, AValue2: integer; const ARemoteLocation: string):string;begin Result:='{"result":"'+(AValue1+AValue2).ToString+'"}';;end;function TkbmMWCustomHTTPSmartService1.EchoString( const AString: string): string;begin result:='{"result":"你好!'+astring+'"}';;end;function TkbmMWCustomHTTPSmartService1.HelloWorld:string;begin Result:='{"result":"Hello world"}';end;

 

转载地址:http://etbda.baihongyu.com/

你可能感兴趣的文章
linux中的计划任务
查看>>
Android style报错
查看>>
【Map】Map、HashMap
查看>>
如何在VMware安装Windows系统
查看>>
Java中高级开发工程师是什么技术水平(附28套Java进阶+高级视频教程)
查看>>
第十九章 文本处理流编辑器:awk编程
查看>>
Xtrabackup+Rsync 备份数据库并同步到远端备份机
查看>>
activiti实战读书笔记——第九章 多实例
查看>>
php返回相对时间(如:20分钟前,3天前)的方法
查看>>
WilliamChart各种图表效果实现大全《IT蓝豹》
查看>>
shell脚本——linux主机监控
查看>>
eclipse配置jsp页面模板
查看>>
基于高德地图写的不同功能的地图应用
查看>>
DHCP服务器配置
查看>>
快速瓶颈识别
查看>>
运维工作总结201403
查看>>
我是菜鸟我加油……mysql主从同步
查看>>
[体系结构]设计模式(五)
查看>>
分布式文件系统
查看>>
其实很简单 微星为你详解Z77主板BIOS设置
查看>>