fpc/packages/fcl-net/examples/rpcserv.pp
peter 00dabb1265 * move uriparser to fcl-base
* move netdb unit and examples to fcl-net
  * removed netdb package

git-svn-id: trunk@9909 -
2008-01-24 23:30:20 +00:00

74 lines
1.5 KiB
ObjectPascal

program RPCServ;
uses SysUtils, Classes, fpAsync, HTTPSvlt, svrclass, svrclass_XMLRPC;
type
TServerApplication = class(TComponent)
private
EventLoop: TEventLoop;
HttpServer: THttpServer;
ServerClass: TServerClass;
XMLRPCServlet: TServerClassXMLRPCServlet;
procedure OnKeyboardData(Sender: TObject);
public
constructor Create;
destructor Destroy; override;
procedure Run;
end;
constructor TServerApplication.Create;
begin
inherited Create(nil);
EventLoop := TEventLoop.Create;
ServerClass := TServerClass.Create;
XMLRPCServlet := TServerClassXMLRPCServlet.Create(Self);
XMLRPCServlet.Name := 'XMLRPCServlet';
XMLRPCServlet.ServerClass := ServerClass;
HttpServer := THttpServer.Create(Self);
HttpServer.EventLoop := EventLoop;
if ParamCount = 2 then
HttpServer.Port := StrToInt(ParamStr(1))
else
HttpServer.Port := 12345;
HTTPServer.AddServlet(XMLRPCServlet, '/xmlrpc');
WriteLn('Listening on port ', HttpServer.Port);
end;
destructor TServerApplication.Destroy;
begin
HTTPServer.Free;
XMLRPCServlet.Free;
ServerClass.Free;
EventLoop.Free;
inherited Destroy;
end;
procedure TServerApplication.Run;
begin
EventLoop.SetDataAvailableNotify(StdInputHandle, @OnKeyboardData, nil);
HttpServer.Active := True;
EventLoop.Run;
end;
procedure TServerApplication.OnKeyboardData(Sender: TObject);
begin
EventLoop.Break;
end;
var
App: TServerApplication;
begin
App := TServerApplication.Create;
try
App.Run;
finally
App.Free;
end;
end.