Recent

Author Topic: Indy on MacOS  (Read 556 times)

egrobler

  • New Member
  • *
  • Posts: 20
Indy on MacOS
« on: December 30, 2020, 11:57:50 am »
Hi,

I am trying this Indy code on Catalina (x86_64-darwin-cocoa) with the firewall disabled. (Lazarus 2.0.11 and FPC 3.2.0)
If I set port 80 I get a message 'Could not bind socket' as expected.

However when I try an open port the app just crashes.

Is macOs terminating my app because of security or is there another cause?
(My app works on Linux but not macOS)

Code: Pascal  [Select][+][-]
  1. procedure TForm1.TestIndy;
  2. var Server : TIdTCPServer;
  3.   Binding: TIdSocketHandle;
  4. begin
  5.   Server := TIdTCPServer.Create(Self);
  6.   Binding := Server.Bindings.Add;
  7.   Binding.IPVersion := Id_IPv4; //optional: forces the Binding to work in Id_IPV4 mode.
  8.   Binding.IP := '127.0.0.1';
  9.   Binding.Port := 9000;  //if Port 80 Message 'Could not bind socket', if port 9000 app crashes
  10.   Server.OnExecute := @OnIndyTestExecute;
  11.   Server.Active := True;
  12. end;
  13.  
  14. procedure TForm1.OnIndyTestExecute(AContext: TIdContext);
  15. begin
  16.    //
  17. end;
  18.  

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 861
Re: Indy on MacOS
« Reply #1 on: December 30, 2020, 12:04:27 pm »
Try running it in the debugger to see where it stops and why.

egrobler

  • New Member
  • *
  • Posts: 20
Re: Indy on MacOS
« Reply #2 on: December 31, 2020, 01:03:20 am »
It crashed when creating a TIdThread.

Seems cthreads must be added in the project file for macOS as well?
However the Lazarus IDE only enables it for Linux?

Code: Pascal  [Select][+][-]
  1.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  2.   cthreads,
  3.   {$ENDIF}{$ENDIF}
  4.  

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 861
Re: Indy on MacOS
« Reply #3 on: December 31, 2020, 01:07:00 am »
Note that it checks for UNIX, not LINUX. UNIX is also defined for Darwin/macOS/iOS. And yes, Darwin indeed also requires cthreads.

egrobler

  • New Member
  • *
  • Posts: 20
Re: Indy on MacOS
« Reply #4 on: December 31, 2020, 03:39:42 am »
//Note that it checks for UNIX, not LINUX

That makes sense, thanks for the help everyone :-)

 

TinyPortal © 2005-2018