Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with Indy TCPClient or IOHandler
(06-28-2018, 08:32 AM)Ayodeji Wrote: We are having some bugs in our application after migrating our source code from delphi 7 to XE2. Indy 9 and  was used in delphi 7 and XE2 respectively. 

I assume you mean Indy 10 in XE2.

(06-28-2018, 08:32 AM)Ayodeji Wrote: Sending of data to the server is done in the Main Thread

That is generally not a good idea. You really should be using a worker thread for that, to avoid blocking the UI.

(06-28-2018, 08:32 AM)Ayodeji Wrote: while reading the response in another Thread.

That is good.

(06-28-2018, 08:32 AM)Ayodeji Wrote: FIdClient.IOHandler.Write(sData + FSendRcvTerminator, TEncoding.ANSI) for sending the data and reading with FClient.IOHandler.ReadBytes(LBuffer, -1, false).

Calling ReadBytes() in that way returns whatever bytes are currently in the socket *at that moment*. Is that what you really want? That runs the risk of receiving partial data, is your code prepared to handle that possibility? Doesn't the communications have structure to it? You are sending a terminator after your outgoing data, does the inbound data have a similar terminator on each message? If so, then why not use IOHandler.ReadLn() or IOHandler.WaitFor() with that terminator passed in as a parameter?

(06-28-2018, 08:32 AM)Ayodeji Wrote: The application do work perfectly for days or weeks without any problem but after a while all the processes in the Main Thread hanged and stop responding

All the more reason NOT to do non-UI work in the main UI thread. It doesn't belong there.

(06-28-2018, 08:32 AM)Ayodeji Wrote: Sending data with FIdClient.IOHandler.Write(sData + FSendRcvTerminator, TEncoding.ANSI)  to the Server from the other Thread gets the hanged processes in Main Thread working again.

Without seeing your actual code, that kind of behavior implies to me that the UI thread is blocked waiting to receive a reply to something it thinks was sent out but really wasn't, so when the worker thread sends it out, it unblocks whatever the UI thread is waiting for.

(06-28-2018, 08:32 AM)Ayodeji Wrote: What are we doing wrong here!

I can't really answer that since you did not show any of your code.


Messages In This Thread
RE: Problem with Indy TCPClient or IOHandler - by rlebeau - 06-28-2018, 05:51 PM

Forum Jump:

Users browsing this thread: 1 Guest(s)