Recent

Author Topic: problem synapse on mac  (Read 3156 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
problem synapse on mac
« on: May 14, 2016, 11:21:12 am »
Hello guys, i have a problem. A simple program made synapse that works well both on linux than on windows on mac does not work. It 'a multithreaded server can query with telnet. Does anyone know if there is any known bug or I have forgotten a parameter?

Launching a terminal server appears this error: ./serverSock
Exception at 00000000: Exception:
.


Thank you

Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: problem synapse on mac
« Reply #1 on: May 14, 2016, 12:04:57 pm »
I solved the first problem, just turn this into lpr file ccodice from this

Code: Pascal  [Select][+][-]
  1. procedure TMyServer.DoRun;
  2. var
  3.   ErrorMsg: String;
  4.   app: TTCPEchoDaemon;
  5. begin
  6.   // quick check parameters
  7.      ErrorMsg:=CheckOptions('h','help');
  8.   if ErrorMsg='' then begin
  9.     ShowException(Exception.Create(ErrorMsg));
  10.     Terminate;
  11.     Exit;
  12.   end;  
  13.  
  14.   // parse parameters
  15.   if HasOption('h','help') then begin
  16.     WriteHelp;
  17.     Terminate;
  18.     Exit;
  19.   end;
  20.  
  21.   { add your program here }
  22.   app:=TTCPEchoDaemon.create;
  23.   app.Execute;
  24.   // stop program loop
  25.   Terminate;
  26. end;    
  27.  

to this (it seems strange that this creates problems, however, solves the problem mentioned above).

Code: Pascal  [Select][+][-]
  1. procedure TMyServer.DoRun;
  2. var
  3.   ErrorMsg: String;
  4.   app: TTCPEchoDaemon;
  5. begin
  6.   // quick check parameters
  7.   {   ErrorMsg:=CheckOptions('h','help');
  8.   if ErrorMsg='' then begin
  9.     ShowException(Exception.Create(ErrorMsg));
  10.     Terminate;
  11.     Exit;
  12.   end;   }
  13.  
  14.   // parse parameters
  15.   if HasOption('h','help') then begin
  16.     WriteHelp;
  17.     Terminate;
  18.     Exit;
  19.   end;
  20.  
  21.   { add your program here }
  22.   app:=TTCPEchoDaemon.create;
  23.   app.Execute;
  24.   // stop program loop
  25.   Terminate;
  26. end;    
  27.  

There remains the problem that when I connect with telnet does not behave as I expect.
Why does the telnet connection to the server, but when trying to send a string (any) the server throws him out. And I do not understand why
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: problem synapse on mac
« Reply #2 on: May 14, 2016, 03:51:01 pm »
Code: Pascal  [Select][+][-]
  1.   ErrorMsg:=CheckOptions('h','help');
  2.   if ErrorMsg='' then begin
  3.  
to this (it seems strange that this creates problems, however, solves the problem mentioned above).
How do you mean strange?
You call CheckOptions and if that states the options are valid (through an ErrorMsg) you show an exception and exit your program.

Did you mean to write?
Code: Pascal  [Select][+][-]
  1.   // quick check parameters
  2.   ErrorMsg:=CheckOptions('h','help');
  3.   if ErrorMsg <> '' then begin                 // NOTICE the  <> instead of =
  4.     ShowException(Exception.Create(ErrorMsg));
  5.     Terminate;
  6.     Exit;
  7.   end;

I'm wondering... you say this program runs on Linux and Windows. ARE YOU SURE? On those, the program would exit immediately, wouldn't it? (without changing that = to <>)

Next... you have
Code: Pascal  [Select][+][-]
  1.   { add your program here }
  2.   app:=TTCPEchoDaemon.create;
  3.   app.Execute;
  4.   // stop program loop
  5.   Terminate;
Here your thread is started and control immediately returns to the main program. That ones terminates... so all started threads also terminate (or are sent the terminate signal).

You shouldn't terminate the main program but wait for the thread to terminate before ending your program.

 

TinyPortal © 2005-2018