Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Closing a TCP/IP component connection the right way
#8
(07-10-2024, 12:09 AM)Ahmed Sayed Wrote: I am always checking if the connection is on via the "Connected" method.

You should not be doing that. Just have your timer/thread read normally and let Indy raise an exception if the connection is closed.

(07-10-2024, 12:09 AM)Ahmed Sayed Wrote: My question is, is that enough to know that the connection has been lost, or do I need to read from the socket to raise the proper errors accordingly?

Since Indy uses blocking sockets, a socket read is necessary. But Indy will read from the socket for you when its InputBuffer doesn't have enough bytes to satisfy a read operation. You don't need to read from the socket yourself, such as with the Connected() method (which does a socket read internally).

(07-10-2024, 12:09 AM)Ahmed Sayed Wrote: Knowing that the client app should not raise exceptions in the user's face everything should be handled internally.

Simply wrap any read/write operation you perform in a try..except (Pascal) or try..catch (C++) block. Indy uses exceptions for all of its error reporting.

Reply


Messages In This Thread
RE: Closing a TCP/IP component connection the right way - by rlebeau - 07-10-2024, 05:03 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)