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

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

本例子基于以前的 使用delphi 10.2 开发linux 上的Daemon

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

加入我们的smart http service.

连接linux 运行.

在浏览器里面访问。

在linux 里面查看进程

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

ok, 跨平台就这么任性。

相关代码

  1. program Project2;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. {$R *.res}
  6. uses
  7. Posix.Unistd,
  8. Posix.SysTypes,
  9. System.SysUtils,
  10. dmp in 'dmp.pas' {dmf: TDataModule},
  11. httpservice in 'httpservice.pas' {kbmMWCustomHTTPSmartService1: TkbmMWCustomHTTPSmartService};
  12.  
  13. procedure daemon;
  14.  
  15. begin
  16.  
  17. dmf:=Tdmf.Create(nil);
  18. dmf.kbmmwserver1.AutoRegisterServices;
  19. dmf.kbmMWServer1.Active:=True;
  20. writeln('service started');
  21. try
  22.  
  23. repeat
  24.  
  25. sleep( * );
  26.  
  27. until False;
  28.  
  29. finally
  30. dmf.Free;
  31. end;
  32.  
  33. end;
  34.  
  35. var
  36. pid: pid_t;
  37.  
  38. begin
  39.  
  40. pid := fork;
  41. if pid = then
  42. begin
  43. writeln('starting service');
  44. daemon;
  45.  
  46. end;
  47.  
  48. end.
  1. unit httpservice;
  2.  
  3. // =========================================================================
  4. // kbmMW - An advanced and extendable middleware framework.
  5. // by Components4Developers (http://www.components4developers.com)
  6. //
  7. // Service generated by kbmMW service wizard.
  8. //
  9. // INSTRUCTIONS FOR REGISTRATION/USAGE
  10. // -----------------------------------
  11. // Please update the uses clause of the datamodule/form the TkbmMWServer is placed on by adding services unit name
  12. // to it. Eg.
  13. //
  14. // uses ...,kbmMWServer,YourServiceUnitName;
  15. //
  16. // Somewhere in your application, make sure to register the serviceclass to the TkbmMWServer instance.
  17. // This can be done by registering the traditional way, or by using auto registration.
  18. //
  19. // Traditional registration
  20. // ------------------------
  21. // var
  22. // sd:TkbmMWCustomServiceDefinition;
  23. // ..
  24. // sd:=kbmMWServer1.RegisterService(yourserviceclassname,false);
  25. //
  26. // Set the last parameter to true if this is the default service.
  27. //
  28. //
  29. // Auto registration
  30. // -----------------
  31. // Make sure that your service class is tagged with the [kbmMW_Service] attribute.
  32. // Then auto register all tagged services:
  33. // ..
  34. // kbmMWServer1.AutoRegisterServices;
  35. //
  36. // -----------------------------------------------
  37. //
  38. // SPECIFIC HTTP SERVICE REGISTRATION INSTRUCTIONS
  39. // -----------------------------------------------
  40. // Cast the returned service definition object (sd) to a TkbmMWHTTPServiceDefinition. eg:
  41. //
  42. // var
  43. // httpsd:TkbmMWHTTPServiceDefinition;
  44. // ..
  45. // httpsd:=TkbmMWHTTPServiceDefinition(sd)
  46. // httpsd.RootPath[mwhfcHTML]:='/';
  47. // httpsd.RootPath[mwhfcImage]:='/images';
  48. // httpsd.RootPath[mwhfcJavascript]:='/js';
  49. // httpsd.RootPath[mwhfcStyleSheet]:='.';
  50. // httpsd.RootPath[mwhfcOther]:='.';
  51. // -----------------------------------------------
  52.  
  53. {$I kbmMW.inc}
  54.  
  55. interface
  56.  
  57. uses
  58. SysUtils,
  59. {$ifdef LEVEL6}
  60. Variants,
  61. {$else}
  62. Forms,
  63. {$endif}
  64. Classes,
  65. kbmMWSecurity,
  66. kbmMWServer,
  67. kbmMWServiceUtils,
  68. kbmMWGlobal,
  69. kbmMWCustomHTTPSmartService ,kbmMWHTTPUtils,
  70. kbmMWSmartServiceUtils,
  71. kbmMWRTTI;
  72.  
  73. type
  74.  
  75. [kbmMW_Service('name:xalionrest, flags:[listed]')]
  76. [kbmMW_Rest('path:/xalionrest')]
  77. // Access to the service can be limited using the [kbmMW_Auth..] attribute.
  78. // [kbmMW_Auth('role:[SomeRole,SomeOtherRole], grant:true')]
  79.  
  80. //[kbmMW_HTTP('accept:[get], root:[media:"webfiles", html:"webfiles"]')]
  81. TkbmMWCustomHTTPSmartService1 = class(TkbmMWCustomHTTPSmartService)
  82. private
  83. { Private declarations }
  84. protected
  85. { Protected declarations }
  86. public
  87. { Public declarations }
  88. // HelloWorld function callable from both a regular client,
  89. // due to the optional [kbmMW_Method] attribute,
  90. // and from a REST client due to the optional [kbmMW_Rest] attribute.
  91. // The access path to the function from a REST client (like a browser)+
  92. // is in this case relative to the services path.
  93. // In this example: http://.../xalionhttp/helloworld
  94. // Access to the function can be limited using the [kbmMW_Auth..] attribute.
  95. // [kbmMW_Auth('role:[SomeRole,SomeOtherRole], grant:true')]
  96.  
  97. [kbmMW_Rest('method:get, path:helloworld')]
  98. [kbmMW_Method]
  99. function HelloWorld:string;
  100.  
  101. [kbmMW_Rest('method:get, path:version')]
  102. [kbmMW_Method]
  103. function version:string;
  104.  
  105. [kbmMW_Method('EchoString')] // 回应输入的串
  106. [kbmMW_Rest('method:get, path: ["echostring/{AString}","myechostring/{AString}" ]')]
  107. [kbmMW_Auth('role:[SomeRole,SomeOtherRole], grant:true')]
  108. function EchoString([kbmMW_Rest('value: "{AString}"')] const AString:string):string;
  109.  
  110. [kbmMW_Method]
  111. [kbmMW_Rest('method:get, path: "cal/addnumbers"')]
  112. function AddNumbers([kbmMW_Rest('value: "$arg1", required: true')] const AValue1:integer;
  113. [kbmMW_Rest('value: "$arg2", required: true')] const AValue2:integer;
  114. [kbmMW_Arg(mwatRemoteLocation)] const ARemoteLocation:string):string;
  115.  
  116. [kbmMW_Rest('method:post, path:postdata')]
  117. [kbmMW_Method]
  118. function postdata:string;
  119.  
  120. end;
  121.  
  122. implementation
  123.  
  124. {%CLASSGROUP 'System.Classes.TPersistent'}
  125.  
  126. uses kbmMWExceptions;
  127.  
  128. {$R *.dfm}
  129.  
  130. // Service definitions.
  131. //---------------------
  132.  
  133. function TkbmMWCustomHTTPSmartService1.version: string;
  134. begin
  135. Result:='{"result":"'+self.Server.Version+':'+TOSversion.ToString +'"}';
  136. end;
  137.  
  138. function TkbmMWCustomHTTPSmartService1.AddNumbers(const AValue1,
  139. AValue2: integer; const ARemoteLocation: string):string;
  140. begin
  141. Result:='{"result":"'+(AValue1+AValue2).ToString+'"}';;
  142. end;
  143.  
  144. function TkbmMWCustomHTTPSmartService1.EchoString(
  145. const AString: string): string;
  146. begin
  147. result:='{"result":"你好!'+astring+'"}';;
  148. end;
  149.  
  150. function TkbmMWCustomHTTPSmartService1.HelloWorld:string;
  151. begin
  152. Result:='{"result":"Hello world"}';
  153. end;

使用delphi-cross-socket 开发kbmmw smart http service的更多相关文章

  1. Delphi跨平台Socket通讯库

    盒子中的souledge大侠发布了新的Socket库,以下为原文: 我之前写过一个iocp的框架,放到googlecode上了. 由于当时的delphi版本尚无法跨平台,所以该框架只能运行在Windo ...

  2. Delphi revelations #1 – kbmMW Smart client on NextGen (Android) – Scope problems

    Delphi 启示 #1 – kbmMW Smart client on NextGen (Android) – 作用域问题 以更高级的方式使用kbmMW smart client,在Android设 ...

  3. delphi 实现微信开发(1) (使用kbmmw web server)

    原文地址:delphi 实现微信开发(1)作者:红鱼儿 大体思路: 1.用户向服务号发消息,(这里可以是个菜单项,也可以是一个关键词,如:注册会员.) 2.kbmmw web server收到消息,生 ...

  4. cross socket tcp客户端开发

    cross socket tcp客户端开发 uses Net.SocketAPI, Net.CrossSocket.Base, Net.CrossSocket FCrossTcp: ICrossSoc ...

  5. Delphi各种Socket组件的模式和模型

    Delphi各种Socket组件的模式和模型 Delphi的大多数书籍里面都没有提到delphi的各种socket通信组件的模式和模型,有的书只讲解了windows的socket模式和模型,并没有归纳 ...

  6. Delphi 跨平台 Socket 通讯库

    Delphi 跨平台 Socket 通讯库 免费开源的Delphi 跨平台 Socket 通讯库. 源码URL:https://github.com/winddriver/Delphi-Cross-S ...

  7. 主窗体里面打开子窗体&&打印饼图《Delphi 6数据库开发典型实例》--图表的绘制

    \Delphi 6数据库开发典型实例\图表的绘制 1.在主窗体里面打开子窗体:ShowForm(Tfrm_Print); procedure Tfrm_Main.ShowForm(AFormClass ...

  8. IOS socket开发基础

    摘要 详细介绍了iOS的socket开发,说明了tcp和udp的区别,简单说明了tcp的三次握手四次挥手,用c语言分别实现了TCPsocket和UDPsocket的客户端和服务端,本文的作用是让我们了 ...

  9. Delphi的Socket编程步骤(repulish)

    转贴自:http://topic.csdn.net/t/20010727/16/212155.html ClientSocket 和ServerSocket几个重要的属性:   1.client和se ...

随机推荐

  1. Android 性能测试之内存 --- 追加腾讯性能案例,安卓抓取性能扫盲帖

    内存测试: 思路 目前做的是酒店APP,另下载安装几个个第三方酒店的APP以方便对比(相当于可以做竞品测试) 数据的获取来源是ADB底层命令,而且最好是不需要root权限,因为很多手机root很麻烦或 ...

  2. 线程 Thread Handler

    new Thread(new Runnable() { @Override public void run() { Message msg = new Message(); msg.what = 0; ...

  3. spring上下文快速获取方法

    import org.springframework.beans.BeansException;import org.springframework.context.ApplicationContex ...

  4. ios系统微信浏览器、safari浏览器中h5页面上拉下滑导致悬浮层脱离窗口的解决方法

    一. 运行环境: iphone所有机型的qq浏览器,safari浏览器,微信内置浏览器(qq浏览器内核)等. 二. 异常现象: 1. 大幅度上下滑动h5页面,然后停止滑动,有时候会影响到页面滚动,如局 ...

  5. 【linux C】C语言中常用的几个函数的总结【二】

    3.fgets 虽然用 gets() 时有空格也可以直接输入,但是 gets() 有一个非常大的缺陷,即它不检查预留存储区是否能够容纳实际输入的数据,换句话说,如果输入的字符数目大于数组的长度,get ...

  6. C++ 智能指针shared_ptr的实现

    #include <memory> #include <iostream> using namespace std; template<typename T> cl ...

  7. SA9 collections

    [定义]  表示object的集合 generic class:可以用于多种object, 抽象类的具体实现: [ArrayList] 动态添加,只能加Non-primitive type,要初始化长 ...

  8. java 线程Thread 技术--1.5 Future与Callable

    Callable: 从官方文档说起: 通过实现callable 的called 方法可以使一个任务可以返回一个结果以及可能抛出一个异常: callable 与runnable 是相似的,可以被其他线程 ...

  9. win下Apache2.4的下载与安装

    1.到apache官网上下载apache的安装文件 http://httpd.apache.org/download.cgi   点击链接Files for Microsoft Windows,因为a ...

  10. npoi设置数据有效性

    npoi设置数据有效性 public void SetDataValidate(ISheet sheet, int firstCol, int lastCol) { CellRangeAddressL ...