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

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

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

我们首先在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( * ); until False; finally
dmf.Free;
end; end; var
pid: pid_t; begin pid := fork;
if pid = 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} interface uses
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;

使用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. jenkin、SVN、archery集成openLDAP

    jenkins: 1.下载.安装插件 LDAP .Matrix Authorization Strategy 2. 系统管理 —> 全局安全配置 点击 启用安全,并且选择 LDAP 认证,这里有 ...

  2. 第三章 列表(d)选择排序

  3. js前端导出excel:json形式的导出

    第一中形式的导出:主要是表头对应主体数据,json形式的导出 js库文件名称 : table2excel.js这个js库文件是网上找的,并且自己根据自己业务需求把内容改了一下复制到 table2exc ...

  4. Git之生成SSH公钥

    一 生成公钥 ssh-keygen -t rsa -C "michelangelo@qq.com" -t :密钥类型. -C :  注释.通常用作密钥的名字. 依次按三次回车:默认 ...

  5. JS判断变量类型

    typeof v 只能用于识别基础类型,不能识别对象 v instanceof MyClass 判断类型 Object.prototype.toString.call(v.p) === "[ ...

  6. PTA 7-8 哈利·波特的考试(floyd)

    哈利·波特要考试了,他需要你的帮助.这门课学的是用魔咒将一种动物变成另一种动物的本事.例如将猫变成老鼠的魔咒是haha,将老鼠变成鱼的魔咒是hehe等等.反方向变化的魔咒就是简单地将原来的魔咒倒过来念 ...

  7. java测试感受

    这个星期四下午来了一次Java考试,用来测试在暑假自学Java的学习情况,不得不说这次考试十分的成功,把我对这学期的学习信心打击的很难受,我也知道这是我应得的教训,我也对我的专业水平有了很深刻的了解了 ...

  8. 【校招面试 之 网络】第2题 TCP的可靠传输、流量控制、滑动窗口

    1.可靠传输 (1)三次握手 TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接: (1)第一次握手:建立连接时,客户端A发送SYN包(SYN=j)到服务器B,并进入SYN_S ...

  9. Django2.0的path方法无法使用正则表达式的解决办法

    本人的django的版本是2.0.6 在django项目中,在urls.py文件中,匹配路由用的path方法,之前我用的都是url方法 写了一个path方法,使用正则表达式 from django.c ...

  10. Aspose.words一 DOM结构

    2.文档对象模型概述 2.1 DOM介绍 Aspose.Words的文档对象模型(以下简称DOM)是一个Word文档在内存中的映射,Aspose.Words的DOM可以编程读取.操作和修改Word文档 ...