Recent

Author Topic: [SOLVED] Compiled indy laz web server on win 7, cannot serve on win 10  (Read 1299 times)

Mongkey

  • Sr. Member
  • ****
  • Posts: 430
My server running well on win7, but do nothing on win 10? Any other had same issue? Thank you

Brook also do nothing on win 10, if i compiled the server on win 7.
No SSL, just simple http server.

Effort:
-setting firewall done
No result .

Does it need to be built on same environment to run?
« Last Edit: February 07, 2023, 12:50:08 am by Mongkey »

nummer8

  • Full Member
  • ***
  • Posts: 108
Re: Built indy laz web server on win 7, cannot serve on win 10
« Reply #1 on: February 06, 2023, 01:45:38 pm »
Hi,

I tested the code below from medium.com written by Marcus Fernström on windows 10
without any issues.

Link to original code:
https://medium.com/@marcusfernstrm/create-rest-apis-with-freepascal-441e4aa447b7


Code: Pascal  [Select][+][-]
  1. program RestApi;
  2. {$mode objfpc}{$H+}uses
  3.   {$IFDEF UNIX}cthreads, cmem,{$ENDIF}
  4.   SysUtils, fphttpapp, httpdefs, httproute, fpjson, jsonparser;
  5.  
  6. procedure jsonResponse(var res: TResponse; data: String);
  7. begin
  8.   res.Content := data;
  9.   res.Code := 200;
  10.   res.ContentType := 'application/json';
  11.   res.ContentLength := length(res.Content);
  12.   res.SendContent;
  13. end;
  14.  
  15. procedure timeEndpoint(req: TRequest; res: TResponse);
  16. var
  17.   jObject : TJSONObject;
  18. begin
  19.   jObject := TJSONObject.Create;
  20.   try
  21.     jObject.Strings['time'] := TimeToStr(Time);
  22.     jsonResponse(res, jObject.AsJSON);
  23.   finally
  24.     jObject.Free;
  25.   end;
  26. end;
  27.  
  28. procedure greetingEndpoint(req: TRequest; res: TResponse);
  29. var
  30.   jObject : TJSONObject;
  31. begin
  32.   jObject := TJSONObject.Create;
  33.   try
  34.     jObject.Strings['greeting'] := 'Hello, ' + req.RouteParams['name'];
  35.     jsonResponse(res, jObject.AsJSON);
  36.   finally
  37.     jObject.Free;
  38.   end;
  39. end;
  40.  
  41. begin
  42.   Application.Port := 9080;
  43.   HTTPRouter.RegisterRoute('/time', @timeEndpoint, true);
  44.   HTTPRouter.RegisterRoute('/greeting/:name', @greetingEndpoint);
  45.   Application.Threaded := true;
  46.   Application.Initialize;
  47.   Application.Run;
  48.  

paweld

  • Hero Member
  • *****
  • Posts: 970
Re: Built indy laz web server on win 7, cannot serve on win 10
« Reply #2 on: February 06, 2023, 01:57:18 pm »
I haven't encountered any problems with a indy http server, I tested on windows 7/10/server 2008/2012/2016/2019
Best regards / Pozdrawiam
paweld

nummer8

  • Full Member
  • ***
  • Posts: 108
Re: Built indy laz web server on win 7, cannot serve on win 10
« Reply #3 on: February 06, 2023, 02:09:40 pm »
Reading properly is very difficult.   :-[
I also tested the INDY http server on windows 10.
No problems.

 

Mongkey

  • Sr. Member
  • ****
  • Posts: 430
Re: Built indy laz web server on win 7, cannot serve on win 10
« Reply #4 on: February 06, 2023, 03:02:29 pm »
Hi, thank you all for your quick replies, i mean compiled on win 7 , then run your exe on win 10 guys  ::), i did a lot server programming by the way  :D
« Last Edit: February 06, 2023, 03:05:26 pm by Mongkey »

paweld

  • Hero Member
  • *****
  • Posts: 970
Re: Compiled indy laz web server on win 7, cannot serve on win 10
« Reply #5 on: February 06, 2023, 04:10:05 pm »
I just now checked and it works without any problem. Compilation on Win7 without sp1 (lazarus 2.2.2/fpc 3.2.2), running on Win7 (checked in IE8) and Win10 (checked in Firefox)
Code: Pascal  [Select][+][-]
  1. const
  2.   page = '<html><head><title>Indy test</title></head>' +
  3.     '<body><center><font size=7><b>Indy test</b></font><br>' +
  4.     '<i>Your IP: {%ip}<br>Your UserAgent: {%agent}</i></center></body></html>';
  5.  
  6. procedure TForm1.FormCreate(Sender: TObject);
  7. begin
  8.   Memo1.Lines.Clear;
  9.   IdHTTPServer1.DefaultPort := 80;
  10.   IdHTTPServer1.Bindings.Add.Port := 80;
  11.   IdHTTPServer1.Active := True;
  12. end;
  13.  
  14. procedure TForm1.FormDestroy(Sender: TObject);
  15. begin
  16.   IdHTTPServer1.Active := False;
  17. end;
  18.  
  19. procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
  20.   ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
  21. var
  22.   pagetmp: String;
  23. begin
  24.   Memo1.Lines.Add(Format('Command: %s, IP: %s, UserAgent: %s', [ARequestInfo.Command, ARequestInfo.RemoteIP, ARequestInfo.UserAgent]));
  25.   pagetmp := StringReplace(page, '{%ip}', ARequestInfo.RemoteIP, [rfReplaceAll]);
  26.   pagetmp := StringReplace(pagetmp, '{%agent}',
  27.     ARequestInfo.UserAgent, [rfReplaceAll]);
  28.   AResponseInfo.ResponseNo := 200;
  29.   AResponseInfo.ContentType := 'text/html';
  30.   AResponseInfo.ContentText := pagetmp;
  31.   Memo1.Lines.Add('---------------------------');
  32. end;  
  33.  
Best regards / Pozdrawiam
paweld

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Compiled indy laz web server on win 7, cannot serve on win 10
« Reply #6 on: February 06, 2023, 07:03:44 pm »
It seems a bogus question. All code works even on win11. Maybe remove it as spam?
Specialize a type, not a var.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Compiled indy laz web server on win 7, cannot serve on win 10
« Reply #7 on: February 06, 2023, 07:34:53 pm »
Code: [Select]
procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  pagetmp: String;
begin
  Memo1.Lines.Add(Format('Command: %s, IP: %s, UserAgent: %s', [ARequestInfo.Command, ARequestInfo.RemoteIP, ARequestInfo.UserAgent]));
  pagetmp := StringReplace(page, '{%ip}', ARequestInfo.RemoteIP, [rfReplaceAll]);
  pagetmp := StringReplace(pagetmp, '{%agent}',
    ARequestInfo.UserAgent, [rfReplaceAll]);
  AResponseInfo.ResponseNo := 200;
  AResponseInfo.ContentType := 'text/html';
  AResponseInfo.ContentText := pagetmp;
  Memo1.Lines.Add('---------------------------');
end; 

Just an FYI, the TIdHTTPServer.OnCommand... events are fired in the context of worker threads, so you need to synchronize with the main UI thread when touching UI controls, like Memo1.
« Last Edit: February 06, 2023, 07:37:27 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Compiled indy laz web server on win 7, cannot serve on win 10
« Reply #8 on: February 06, 2023, 07:37:06 pm »
My server running well on win7, but do nothing on win 10?

You need to be MUCH more specific.

What EXACTLY is not working for you?  Are you getting any errors?  Are you running your HTTP clients on the same machine as your HTTP server, or are they connecting to your HTTP server over a LAN, or the Internet?  Are the clients able to connect to your HTTP server at all, but are just not able to send requests and/or receive responses?  Have you tried sniffing the network with a packet sniffer like Wireshark to see if there are any traffic issues?

How do you expect people to help you when you don't explain WHAT is going wrong for you?

Brook also do nothing on win 10, if i compiled the server on win 7.

What is Brook?

Does it need to be built on same environment to run?

No.
« Last Edit: February 06, 2023, 07:40:41 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Mongkey

  • Sr. Member
  • ****
  • Posts: 430
Re: Compiled indy laz web server on win 7, cannot serve on win 10
« Reply #9 on: February 07, 2023, 12:49:37 am »
Hello remy, indy worked over windows, i already inspect all of my code, i forgot, i was dissabling binding for spesific port, sorry  :D. Brook is another lazarus web server component using libhttpd, brook worked also, the problem is just my firebird on win 10. Thank you all.

This prototype is using indy as data streamer over network.
Thank you.


« Last Edit: February 07, 2023, 01:02:57 pm by Mongkey »

 

TinyPortal © 2005-2018