Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1329
  • Last Modified:

idtcpclient problem

I've got some code like the following on client side. The TCPServer is
handling everything with command handlers.
In the following code, the first response to command 'RINI' is working
all fine. However, on the following sendcmd(RDBNAMES) line, the client
is freezing. In the meantime, the idtcpclient.connect method is in
initialization and i want the client application to be connected to
the server all times until application.terminate.

What am i doing wrong in this freezing line?

begin
  TCPForm.IdTCPClient1.Host:=rHost_Address;
  TCPForm.IdTCPClient1.Port:=rHost_Port;
  try
   TCPForm.IdTCPClient1.Connect(5000);
  except
   on E : Exception do ShowMessage(E.Message);
  end;
  try
   rcvstr:=Tstringlist.Create;
   remoteinifile:=Tmeminifile.Create('');
   TCPForm.IdTCPClient1.SendCmd('RINI');
   TCPForm.IdTCPClient1.Readstrings(rcvstr,-1);
   remoteinifile.SetStrings(rcvstr);
   rInit_Sysaudit       := remoteinifile.ReadBool('INIT', 'SYSAUDIT',
False);
   rLogin_Optionsfolder := remoteinifile.ReadString('LOGIN',
'OPTIONSFOLDER', '');
   rDirectories_DefaultDir := remoteinifile.ReadString('DIRECTORIES',
'DEFAULTDIR', '');
  finally
   rcvstr.Free;
   remoteinifile.Free;
  end;
  try
   DBnames:=Tstringlist.Create;
   TCPForm.IdTCPClient1.SendCmd('RDBNAMES');
   
-->Freezing in the following line!

   TCPForm.IdTCPClient1.Readstrings(DBNames,-1);
   combobox1.items.addstrings(DBnames);
  finally
   DBNames.free;
  end;
end;

Thanks in advance,
0
febalci
Asked:
febalci
1 Solution
 
MaximilianopCommented:
Hello febalci.
  In response to your topic i'm wirting the next:
  I happend to crush onto the same problem once, and I fixed it in a realy simple way:
  Onto the CommandHandler's OnCommand event, First of all I wrote the next line, Asender.SendReply; , I don't quite know way, but it seems even if the server object sends the response automatically the client objects doesn't detect it like that, and keeps waiting for the response, so if you wanna send another command, it will wait until response timeout, before sending it, also freezing that part of the thread.

  So Go to you server's object CommandHandlers property, and select the onw which triggers with 'RINI', then go to the event OnCommand, and on it Write Asender.SendReply; and it shouldn't freeze on the next command you send.
  And here comes the ugly part: You must repeat the process for every command, if one doesn't have it (including the quit one), the client will not be able to process anything more (not even the disconnection).

  Other way to fix it is to set a Timeout, but, I wouldn't do it since Response time depends on the connection, and some may be very unstable.

Ohh, and by the way it freezes while procesing the TCPForm.IdTCPClient1.SendCmd('RDBNAMES'); line, instead of the following one, the trace doesn't show it, but the previous line stays trapped in a loop.
0
 
febalciAuthor Commented:
Thanks a lot,works fine now...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now