Recent

Author Topic: Failed to connect to a simple web server  (Read 986 times)

ap3000

  • New Member
  • *
  • Posts: 36
Failed to connect to a simple web server
« on: February 08, 2025, 07:49:24 pm »
In preparation for making a Rest API webserver, I searched for some examples and found this one:

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

This compiling and running fine on my Windows 10 machine. But I just got a new laptop running Windows 11 and I can't connect to the server. I get the "ERR_CONNECTION_REFUSED".

I have tried to shut off the firewall without a result. What can I more do to get this working?


Anders Pedersen

MarkMLl

  • Hero Member
  • *****
  • Posts: 8315
Re: Failed to connect to a simple web server
« Reply #1 on: February 08, 2025, 07:55:11 pm »
I am no expert in this area, but in the interest of getting something going: is your client telling you that it wants https rather than http at the server end?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

ap3000

  • New Member
  • *
  • Posts: 36
Re: Failed to connect to a simple web server
« Reply #2 on: February 08, 2025, 08:26:35 pm »
Hi Mark,

I'm not sure. It also doesn't with https. de server is only lisent to HTTP. As it works on Windows 10 it has to be something on this laptop. To exclude that it was the browser (Brave) I also tried it with Postman - same result

Sorry I was not correct the error is "ERR_UNSAFE_REDIRECT"
« Last Edit: February 08, 2025, 08:43:17 pm by ap3000 »
Anders Pedersen

silvercoder70

  • Full Member
  • ***
  • Posts: 157
    • Tim Coates
Re: Failed to connect to a simple web server
« Reply #3 on: February 08, 2025, 09:54:18 pm »
I suspect that it is forcing the browser to use https?

The code does work out of the box - just ran it on linux mint and connected fine via Firefox. Try out this link ...

https://superuser.com/questions/1400200/chrome-persistently-redirecting-to-https-for-http-site
Explore the beauty of modern Pascal programming with Delphi & Free Pascal - https://www.youtube.com/@silvercoder70

egsuh

  • Hero Member
  • *****
  • Posts: 1555
Re: Failed to connect to a simple web server
« Reply #4 on: February 09, 2025, 08:26:42 am »
I don't think this is the cause of the problem, but is port 8090 available?

jcmontherock

  • Sr. Member
  • ****
  • Posts: 282
Re: Failed to connect to a simple web server
« Reply #5 on: February 09, 2025, 10:54:36 am »
Did you change the port in file ? 8090 or 9080
Windows 11 UTF8-64 - Lazarus 4.0RC2-64 - FPC 3.2.2

ap3000

  • New Member
  • *
  • Posts: 36
Re: Failed to connect to a simple web server
« Reply #6 on: February 09, 2025, 09:19:07 pm »
Hi @jcmontherock Yes I changed the port to 9080 and No @egsuh, the 9080 port is available -  checked with netstat -an.

But the netstat shows it as Local address 127.0.0.1:9080 and foreign address 127.0.0.1:49258 CLOSE_WAIT.
But also as Local address 127.0.0.1:9080 and foreign address 0.0.0.0 LISTENING.
See screen shots

Can someone tell me what it's mean?
 
But changed the port to 9081 and now it is working.
Anders Pedersen

MarkMLl

  • Hero Member
  • *****
  • Posts: 8315
Re: Failed to connect to a simple web server
« Reply #7 on: February 09, 2025, 09:53:25 pm »
It means that something's connected to it (not necessarily successfully) and that the port doesn't have the option set that allows immediate reconnection.

This is something that I've previously wrestled with in the context of LNet's Telnet implementation, which was so screwed up that I ended up writing my own: see https://github.com/MarkMLl/telnetsrv/blob/main/telnetserver.pas line 888.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

ap3000

  • New Member
  • *
  • Posts: 36
Re: Failed to connect to a simple web server
« Reply #8 on: February 09, 2025, 09:58:24 pm »
Thanks Mark
Anders Pedersen

MarkMLl

  • Hero Member
  • *****
  • Posts: 8315
Re: Failed to connect to a simple web server
« Reply #9 on: February 09, 2025, 10:16:12 pm »
BTW, kudos to you for using netstat properly ;-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018