In the previous article, we discussed the various ways in which we can create indy servers. Picking up from where we left off, in this article we are going to build a server application using the CommandHandler method.
Using the Command Handler Method in Delphi - Implementing the Second and Third Commands (Page 2 of 5 )
Now, we need to implement the second command. So repeat what you did before except this time, add "Adate" to the command property. Then, to the Oncommand event, add the following code:
ASender.Context.Connection.IOHandler.WriteLn('Today''s date is: '+FormatDateTime(AFormat, Now));
end;
Again, this is a straightforward procedure that sends today's date to the requesting client. The AFormat variable formats the date so that it is displayed in the form of year-month-day hour:mins:secs. The "Now" word in the line
ASender.Context.Connection.IOHandler.WriteLn('Today''s date is: '+FormatDateTime(AFormat, Now));
gets the current date and time.
Repeat the process and let's implement the final command, which is to close down the connection. Add "quit" to the command property and to the Oncommand event add the following code:
This procedure closes down the connection with this particular client. The other connected clients will still be connected. If you remember our previous discussions, you will recall that we used the term "context" a lot. This is because each client is dealt with, within its own context. Hence the "ASender.Context.Connection.Disconnect;".