Welcome, Guest
Username: Password: Remember me
Components and Libraries for Networking Development, discussions, problems and suggestions
  • Page:
  • 1

TOPIC:

Cannot create a simple HTTP Server Daemon 10 years 10 months ago #5036

  • Marco Pinero
  • Marco Pinero's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 0
I'm using CT 4.5 on Linux. I would like to create a simple http server by creating a new daemon app project (in order to add more functionality to my future app).

I drop an IdHTTPServer on daemon1 and then I define my TDaemon1 like:
uses
  Classes, SysUtils, FileUtil, IdHTTPServer, DaemonApp, Interfaces, IdCustomHTTPServer,
  IdContext, IdGlobal;

type

  { TDaemon1 }

  TDaemon1 = class(TDaemon)
    IdHTTPServer1: TIdHTTPServer;
    procedure DataModuleCreate(Sender: TObject);
    procedure DataModuleExecute(Sender: TCustomDaemon);
    procedure IdHTTPServer1CommandGet(AContext: TIdContext;
      ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Daemon1: TDaemon1;

implementation

procedure RegisterDaemon;
begin
  RegisterDaemonClass(TDaemon1)
end;

{$R *.lfm}

{ TDaemon1 }

procedure TDaemon1.DataModuleCreate(Sender: TObject);
begin
  IdHTTPServer1.Bindings.Add.IPVersion:=Id_IPv4;
  IdHTTPServer1.DefaultPort:=8081;
  IdHTTPServer1.Active:=true;
end;

procedure TDaemon1.DataModuleExecute(Sender: TCustomDaemon);
begin

end;

procedure TDaemon1.IdHTTPServer1CommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
  AResponseInfo.ContentType:='text/plain';
  AResponseInfo.ContentText:='Hello world!';
  AResponseInfo.WriteHeader;
  AResponseInfo.WriteContent;
end;

initialization
  RegisterDaemon;
end.  

i test it using command "> server -r", but port is not open. no response for "localhost:8081" or "> telnet localhost 8081 --> connection refused".

What's wrong here?

What's the simplest way to create a daemon app with http service capabilities without using webserver project template?

Thanx in advance.

Please Log in or Create an account to join the conversation.

Cannot create a simple HTTP Server Daemon 10 years 10 months ago #5037

  • zeljko
  • zeljko's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 207
  • Thank you received: 38

Please Log in or Create an account to join the conversation.

Cannot create a simple HTTP Server Daemon 10 years 10 months ago #5038

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
and this sample with some other is in CT CodeOcean Session
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

Cannot create a simple HTTP Server Daemon 10 years 10 months ago #5040

  • Marco Pinero
  • Marco Pinero's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 0
This example is useless for me.

I need a daemon app, because this app will be installed on linux server without graphic desktop.

Is there any way to make it works using "daemon application" (not application).

Thanx

Please Log in or Create an account to join the conversation.

Cannot create a simple HTTP Server Daemon 10 years 10 months ago #5041

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
My suggestion
make a Daemon (service) application and load all Indy Server Comp to Daemon Module
please use CT 4.7

PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

Last edit: by Sternas Stefanos.

Cannot create a simple HTTP Server Daemon 10 years 10 months ago #5042

  • Marco Pinero
  • Marco Pinero's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 0
Thanx for responses, but that's what I did. And nothing happens.

I showned in the code. Nothing happens. :S

Please Log in or Create an account to join the conversation.

Cannot create a simple HTTP Server Daemon 10 years 10 months ago #5043

  • Marco Pinero
  • Marco Pinero's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 0
Downloading CT4.7

Please Log in or Create an account to join the conversation.

Cannot create a simple HTTP Server Daemon 10 years 10 months ago #5050

  • Marco Pinero
  • Marco Pinero's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 0
Same problem.

No difference using CT4.7

Please help!

Please Log in or Create an account to join the conversation.

Cannot create a simple HTTP Server Daemon 10 years 10 months ago #5051

  • Marco Pinero
  • Marco Pinero's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 13
  • Thank you received: 0
I got it.

I made it work by adding my Daemon Class in Daemondefs property of mapper unit. But i got other problems:

In order to make it work with Indy (idHTTPServer), I had to use "interfaces" unit (because if not multiple errors raise). But, reading some documents at internet about "daemons" with Lazarus, daemos may not use "interfaces" unit because this causes a LCL dependency, making dameon app crashes because LCL is used for graphical desktop. When I try tu run my daemon it shows this error: Gtk-WARNING **: cannot open display, and it does not start.

How can I use Indy comps or LNetComps (sockets) without using this "interfaces" unit??

Remember: I am trying to get a simple HTTP Server Daemon, using pot 80 and additionally including listening other ports (tcp) for other custom services.

Thanx in advance.

Please Log in or Create an account to join the conversation.

Cannot create a simple HTTP Server Daemon 10 years 9 months ago #5114

  • zeljko
  • zeljko's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 207
  • Thank you received: 38
exampl : Howto write a server that runs on linux with freepascal
www.pascalgamedevelopment.com/showthread...ith-freepascal/page2

compile and not work, a different way of solving

If you manage to write

Please Log in or Create an account to join the conversation.

Cannot create a simple HTTP Server Daemon 10 years 9 months ago #5194

  • zeljko
  • zeljko's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 207
  • Thank you received: 38
send example work linux daemon http server
exampl to CodeTyphon

File Attachment:

File Name: idserver_daemon.zip
File Size:4 KB

Please Log in or Create an account to join the conversation.

Last edit: by zeljko.

Cannot create a simple HTTP Server Daemon 10 years 9 months ago #5195

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
Thanks Sir
can we add this to CodeOcean ?
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

  • Page:
  • 1