Archived Forum Post

Index of archived forum posts

Question:

How to trigger an event that calls my application when something external happens?

Oct 29 '13 at 19:38

I looked through the forums and couldn't seem to find this information. Is there an event that I can trigger when the remote host disconnects an SSH connection? Say for example, to close a terminal if the remote side ends the connection?


Answer

I get this kind of question from time to time. The answer is that you only need to remember the most fundamental thing about computer programs -- that they are series of instructions executed one after the other.

What is an "event callback"? It's where your application essentially provides a function pointer that will be called back from within the called method. Let's follow the thread of execution:

  1. Your application is executing code one statement after the other.
  2. It makes a call into a Chilkat method.
  3. Now the code internal to the Chilkat method is executing one statement after the other.
  4. A call is made to a function in your application via the callback function pointer. Now your application is executing code one statement after another.
  5. The callback function returns, reverting control back to the Chilkat internal code, which is now executing one statement after the other.
  6. The Chilkat method returns, reverting control back to your application, which continues executing one statement after the other.

To answer your question: Chilkat would only know about the disconnect if it was actively trying to read/write the socket. That can only happen when your application has made a Chilkat method call and the thread of execution is within the Chilkat method. Upon a disconnect, it wouldn't be an event that is raised, but it would simply cause the Chilkat method call to return.