[SOLVED] Compiled indy laz web server on win 7, cannot serve on win 10
lazarus / 34-Windows
----------------------------------------------------------------------
Mongkey · 2023-02-06 10:55
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?
----------------------------------------------------------------------
nummer8 · 2023-02-06 12:45
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][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i program
RestApi;{$mode objfpc}{$H+}uses {$IFDEF UNIX}cthreads, cmem,{$ENDIF}
SysUtils, fphttpapp, httpdefs, httproute, fpjson,
jsonparser; procedure jsonResponse(var res: TResponse; data:
String);begin res.Content := data; res.Code := 200; res.ContentType
:= 'application/json'; res.ContentLength := length(res.Content);
res.SendContent;end; procedure timeEndpoint(req: TRequest; res:
TResponse);var jObject : TJSONObject;begin jObject :=
TJSONObject.Create; try jObject.Strings['time'] :=
TimeToStr(Time); jsonResponse(res, jObject.AsJSON); finally
jObject.Free; end;end; procedure greetingEndpoint(req: TRequest; res:
TResponse);var jObject : TJSONObject;begin jObject :=
TJSONObject.Create; try jObject.Strings['greeting'] := 'Hello, ' +
req.RouteParams['name']; jsonResponse(res, jObject.AsJSON);
finally jObject.Free; end;end; begin Application.Port := 9080;
HTTPRouter.RegisterRoute('/time', @timeEndpoint, true);
HTTPRouter.RegisterRoute('/greeting/:name', @greetingEndpoint);
Application.Threaded := true; Application.Initialize;
Application.Run;
----------------------------------------------------------------------
paweld · 2023-02-06 12:57
I haven't encountered any problems with a indy http server, I tested
on windows 7/10/server 2008/2012/2016/2019
----------------------------------------------------------------------
nummer8 · 2023-02-06 13:09
Reading properly is very difficult.
I also tested the INDY http server on windows 10.
No problems.
----------------------------------------------------------------------
Mongkey · 2023-02-06 14:02
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
----------------------------------------------------------------------
paweld · 2023-02-06 15:10
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][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i const page
= '
Indy test' +
'Indy test
' + 'Your
IP: {%ip}
Your UserAgent:
{%agent}'; procedure
TForm1.FormCreate(Sender: TObject);begin Memo1.Lines.Clear;
IdHTTPServer1.DefaultPort := 80; IdHTTPServer1.Bindings.Add.Port :=
80; IdHTTPServer1.Active := True;end; procedure
TForm1.FormDestroy(Sender: TObject);begin IdHTTPServer1.Active :=
False;end; 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;
----------------------------------------------------------------------
Thaddy · 2023-02-06 18:03
It seems a bogus question. All code works even on win11. Maybe remove
it as spam?
----------------------------------------------------------------------
Remy Lebeau · 2023-02-06 18:34
Quote from: paweld on February 06, 2023, 04:10:05 pmCode:
[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.
----------------------------------------------------------------------
Remy Lebeau · 2023-02-06 18:37
Quote from: Mongkey on February 06, 2023, 11:55:59 amMy 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?
Quote from: Mongkey on February 06, 2023, 11:55:59 amBrook also do
nothing on win 10, if i compiled the server on win 7.
What is Brook?
Quote from: Mongkey on February 06, 2023, 11:55:59 amDoes it need to
be built on same environment to run?
No.
----------------------------------------------------------------------
Mongkey · 2023-02-06 23:49
Hello remy, indy worked over windows, i already inspect all of my
code, i forgot, i was dissabling binding for spesific port, sorry .
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.