How to build server application on Linux with kbmmw?
Starting from kbmmw 5.01, Delphi 10.2 and Linux are officially supported.
Today we will build a kbmmw server application for linux server.
This example is based on the last linux Daemon example.
If you are not familiar with it, please read the above article first.
First put kbmmwserver and kbmMWTCPIPIndyServerTransport in the datamodule
Two controls.
As shown in the figure, and set the corresponding value.
Then establish a standard service
Generate corresponding services and functions.
Add the code to build the service in the DataModule.
procedure Tdmf.DataModuleCreate (Sender: TObject);
was
sd:TkbmMWCustomServiceDefinition;
begin
sd:=kbmMWServer1.RegisterService(TkbmMWInventoryService,false);
sd:=kbmMWServer1.RegisterService(Txalionsrv,false);
end;
The main program code is as follows:
program Project2;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Posix.Unistd,
Posix.SysTypes,
System.SysUtils,
dmp in 'dmp.pas' {dmf: TDataModule},
srv_yw in ' srv_yw.pas ' { xalionsrv: TkbmMWSimpleService } ;
procedure daemon;
begin
dmf:=Tdmf.Create(nil);
dmf.kbmmwserver1.Active: = True;
writeln('service started');
try
repeat
sleep(10 * 1000);
until False;
finally
dmf.Free;
end;
end;
where
pid: pid_t;
begin
pid := fork;
if pid = 0 then
begin
writeln('starting service');
daemon;
end;
end.
Compile and run this program under linux.
After the program exits, a service is automatically created in the background.
Ok, we access this program on the client side.
It seems that there is no problem, writing a Linux server with kbmmw is as simple as that.
Comment disabled