Implementing a TIdCmdTCPServer without using reply codes

Is there an easy way to implement a TIdCmdTCPServer without using reply codes?  I'm wanting to migrate an existing server from ICS to Indy, but I need to maintain textual command compatibility so that the older versions of the client can still communicate with the new service.  For example, my current service sends a "greeting" and the client expects to receive that greeting.  But if I set Greeting.Reply.Code := EmptyStr, no greeting appears even though I have the greeting text set.

From reading Indy in Depth, I was concerned about how easy it would be to use Indy if my service's protocol doesn't use reply codes.  Granted, reply codes are a great idea.  But I need to maintain compatibility with client applications that have been connecting to this service for the past 8 years.

Thanks
0
Jon
4/20/2015 9:22:38 PM
embarcadero.delphi.winsock 1874 articles. 2 followers. Follow

6 Replies
776 Views

Similar Articles

[PageSpeed] 53

Jon wrote:

> Is there an easy way to implement a TIdCmdTCPServer without using
> reply codes?

Reply codes are not mandatory, as long as there is text assigned.  HOWEVER, 
TIdReplyRFC (which is the default TIdReply class used by TIdCmdTCPServer) 
does not allow NumericCode 0.  So although you can clear the Greeting.Code 
and assign just the Greeting.Text, TIdCmdTCPServer will go through the motions 
of preparing to send the Greeting and crash, disconnecting the client, when 
TIdCmdTCPServer.DoConnect() assigns such a Greeting to a temp TIdReplyRFC 
for transmission.  That might actually be a bug in TIdReplyRFC.AssignTo(), 
as it converts a blank Code to NumeriCode 0 during assignment.

So, if you want a no-code Greeting, you will have to either:

1. derive a new class from TIdReplyRFC and override its virtual CheckIfCodeIsValid() 
method to not raise an exception when the input value is '0', and then derive 
a new component from TIdCmdTCPServer and override its GetReplyClass() method 
to return your custom TIdReply class.

2. just disable the TIdCmdTCPServer.Greeting property and send your own custom 
text in the TIdCmdTCPServer.OnConnect event.

> I'm wanting to migrate an existing server from ICS to Indy, but I need
> to maintain textual command compatibility so that the older versions of
> the client can still communicate with the new service.  For example, my
> current service sends a "greeting" and the client expects to receive that
> greeting.  But if I set Greeting.Reply.Code := EmptyStr, no greeting
> appears even though I have the greeting text set.

That is because the TIdReply.Code property setter clears the TIdReply.Text 
property.  Without a Code or Text, there is no reply data to send.

-- 
Remy Lebeau (TeamB)
0
Remy
4/20/2015 3:50:05 PM
> {quote:title=Jon Robertson wrote:}{quote}
> Is there an easy way to implement a TIdCmdTCPServer without using reply codes?

I'm going to try writing my own TIdReply class that allows replies to be sent without using a reply code.  I'm not sure at this point whether that is all that is necessary.  If it works, after creating the TIdCmdTCPServer object, I'll iterate through all of the TIdReply properties, free them, and then assign a new instance of my TIdReply class.
0
Jon
4/20/2015 9:31:16 PM
Jon wrote:

> If it works, after creating the TIdCmdTCPServer object, I'll iterate through
> all of the TIdReply properties, free them, and then assign a new instance
> of my TIdReply class.

You don't need to go that far, nor should you.  To use a custom TIdReply 
class, all you have to do is derive a new component from TIdCmdTCPServer 
and override its GetReplyClass() (and GetRepliesClass()) method(s).

-- 
Remy Lebeau (TeamB)
0
Remy
4/20/2015 10:05:11 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> just avoid the Response property and stick with the TIdCommand.Reply.Text 
> property only.

Fantastic.  Thanks again.

> If you really want to customize the replies beyond what TIdCommandHandler 
> is capable of, then you will have to set the TIdCommandHandlers.PerformReplies 
> or TIdCommand.PerformReply property to False, and then you can write your 
> own data in the TIdCommandHandler.OnCommand event directly to TIdCommand.AContext.Connection 
> using whatever formatting you want.

Good to know, although it looks like I'm able to achieve what I want using the advice you've given.

I've read the "Indy in Depth" paper a few times, including a fresh read just yesterday, and I reference the docs at http://www.indyproject.org/docsite/html/ quite a bit.  But I've learned things from your responses that aren't explained in either location.  I really appreciate your help.  I may have to spend time reading everything in this newsgroup to learn more about using Indy directly.  I cut my teeth on ICS back in 1996 and used it almost exclusively since then.  But my implementations of a asynchron
ous/event/state machine to work with non-blocking components is difficult to maintain and debug.  I just started converting my services to Indy and so far I'm very pleased with it.  :)

Jon
0
Jon
4/21/2015 1:01:01 AM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> You don't need to go that far, nor should you.  To use a custom TIdReply 
> class, all you have to do is derive a new component from TIdCmdTCPServer 
> and override its GetReplyClass() (and GetRepliesClass()) method(s).

Thanks Remy!  That worked perfectly.

Is there any easy way to stop TIdCmdTCPServer from writing out the terminating line containing a single period?  TIdTCPConnection.WriteRFCStrings is not virtual, but it uses the designated IOHandler class.  Unfortunately, TIdIOHandler.WriteRFCStrings is not virtual, so I can't simply derive a new class from TIdIOHandler and override the behavior.  I suppose I can copy the entire TIdIOHandler class to a new class and modify just WriteRFCStrings.  Unfortunately, that'll require additional maintenance and te
sting as we apply Delphi updates or upgrade to new versions.

Jon
0
Jon
4/21/2015 1:32:08 PM
Jon wrote:

> Is there any easy way to stop TIdCmdTCPServer from writing out
> the terminating line containing a single period?

It only does that if you are putting data in the TIdCommand.Response or TIdCommandHandler.Response 
property, or setting the TIdCommand.SendEmptyResponse property to true.  
TIdCommandHandler sends the Response data using the TIdConnection.WriteRFCStrings() 
method, which doubles a preceeding dot on each line and then ends the data 
with a terminating dot.  Protocols like FTP, POP3, SMTP, etc require such 
dot escaping.  So, just avoid the Response property and stick with the TIdCommand.Reply.Text 
property only.

> Unfortunately, TIdIOHandler.WriteRFCStrings is not virtual, so I can't
> simply derive a new class from TIdIOHandler and override the behavior.

Nor should you be trying to change its behavior.  WriteRFCStrings() is designed 
for a particular style of protocol, which is obviously different than your 
protocol.

If you really want to customize the replies beyond what TIdCommandHandler 
is capable of, then you will have to set the TIdCommandHandlers.PerformReplies 
or TIdCommand.PerformReply property to False, and then you can write your 
own data in the TIdCommandHandler.OnCommand event directly to TIdCommand.AContext.Connection 
using whatever formatting you want.

-- 
Remy Lebeau (TeamB)
0
Remy
4/21/2015 5:37:18 PM
Reply:

Similar Artilces:

[D2010] Can I use Assembly code in my Delphi code?
Hello all, I am new to Delphi, and I am just installing the trial version, but I have some question. Can I use assembly code without restrictions in my Object Pascal/Delphi code? Many thanks! Greets DelphiLynx I'm not quite certain what you mean by "without restriction", but yes you can use assembly code. I don't believe how to do so is documented though. However, you can look at VCL for some examples. Search in the VCL for ASM and you should find some. A quick google search also found this: http://delphi.about.com/library/bluc/text/uc052501a.htm none no...

event handling in asp.net (vb.net ) using code behind without using Visual studio ID
************* Edited by moderator Adec *************** Inserted missing < code></ code> tags (without the spaces inside). Always include such tags when including code in your postings. Don't force the moderators to do this for you. Many readers disregard postings without the code tags. ************************************************** Hi everyone, i am not able to make a event handler in asp.net using vb.net in code behind page, Yes I am not using visual studio ID, I am hard coding it each and every thing. Please suggest me and if possible give me...

To use or not to use Delphi
Sadly, it seems to me that there is a sort of race between the two threads, for and against using Delphi in new projects, with more or less the same users posting in both threads. Arguments are fiercely debated in both camps. Borland had their own vision. As a community, now that Delphi has changed ownership I believe we should try to be more consistent, more clear, and more articulate in what we expect from Embercadero in terms of Delphi. We can contribute to keeping Delphi alive and moving in the right direction. "Laurent Cocea" schrieb: > Sadly, it seems to me that there ...

Code regardin post: Spread 8 COM
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --JivePart=_5f856.zeB8CwDOH5aMJzMl Content-Type: text/plain; charset="Utf-8" Code samples Spread Custom Cell Sample.zip = Delphi code Spread_ActiveX_Samples.zip = GrapeCity sample (VB, VC) -- Regards, Ronald Hoek Application Developer ComponentAgro B.V. Oud-Beijerland - The Netherlands http://www.componentagro.nl KvK: H24264020 --JivePart=_5f856.zeB8CwDOH5aMJzMl Content-Type: application/zip; name="Spread_Act...

How to call or retrieve fields from sql and display in table without using ADO.net, I'm using a dynamic link library....Is the coding different?
Help me! I'm doing my school project on Software Change Management Tool, CR Tracker. I want to display table in the webform, and the table data is retrieve form the sql server. So how do I call the sql so as to display the data in a table? hy..What does that dll contain ?Does it already contains relevant code to connect to a database ? Have a look hereThanksDinuj Nath The easy way to do this is with the use of a data bound grid. The Grid can be customised to look and feel you like. You will need to add a data adapter to your page and a grid. When you setup the data adapter you will nee...

use hidden code or write the code using html platform
i confuse which one is better if i use hidden code with write the coding into <namefile>.aspx.vb or just write in html platform that provided in vs.studio.net. i think if i write the coding in html platform... what the different if i use asp than asp.net. what others viewing with my problem....Percaya pada kebolehan sendiri by "hidden code" i assume you mean code-behind. i use code-behind as much as possible because the programming environment is much more friendly - e.g. auto-code completion, underlining, etc. but it does require deployment of DLLs. not using code...

Using delphi code in C++ builder?
Hi there, How do I go about integrating delphi code into a C++ builder (2007) project. We have a delphi developer that wants to contribute. Is this possible in C++ builder 2007? We also own RAD Studio 2009 licences. I could probably work this out myself but why waste my time when someone here already knows the answer!!! Thanks in advance... Ashley "Ashley Duncan" wrote in message news:214785@forums.codegear.com... > How do I go about integrating delphi code into a C++ builder (2007) > project. Add the .pas files to the project. You won't be abl...

Sharing Code Without Using GAC
Hey Everyone, This is my first post here so I'm crossing my fingers. Here is my situation. I've got a complete ASP .NET application with a pretty decent seperation of code and content. At least decent for my first attempt at this. Anyway what I want to do which I'm sure you've guessed is run multiple sites from one set of compiled files. All I want to copy from site to site is the .aspx files. How do I got about doing this without using the GAC. Is it even possible? Thanks Yes its possible you can redirect the probing for the DLL to a common shared directory. All you need to ...

On Using C++ code from Delphi [Edit]
Hello, one of the most frequently requested - but never realized - features for Delphi is the ability to use C++ code. I'd like to know about your needs regarding C++, and how you think about such a feature. - Is it critical for you to be able to use 3rd-party C++ libraries and C++ classes in Delphi without further changes or additional work? - Or do you want to use VCL components written in C++ in your Delphi projects? - Imagine a solution that makes C++ classes visible to Delphi code, with the following restrictions: o the C++ code needs to be built with C++Builder, o t...

Transferring Delphi 5 BDE code to Delphi 2006 Nexus Embedded server code
In an application where I have used BDE in Delphi 5 I would like to transfer the whole project to Nexus Embedded server that in general implies mostly exchanging tTable with tnxTable etc. But, in a procedure I regenerate indexes using dbiRegenIndexes(basehandler). This function seems not to be supported anymore, so I just wonder if such a call is needed at all in Nexus Embedded Server, and if needed, what is now the correct syntax ?? I don't know the answer to your question but if you can't find answers here you may like to know that nexus db have there own free newsgr...

Which datatype to store mobile no without code no...be used ??
 Hello Frdz,                I have doubt regarding the datatypes fields used in  SQL SERVER 2005.I want to use the field to store the mobile number of the user .Which datatype should i used ??  The value for bigint Int64 is 18The value of int Int32 is 9/10Now,if in int i write : 1234567890 (accepted)This gives error     :  9874565656 (not accepted..........why is it so      ???     )Why is it so ??I want to know the perfect size of al...

Unzip tree in Delphi without DLLs
Using Delphi 2009, I need to unzip a tree of files in a Zip file to a given directory, with the ability to overwrite existing files, ideally free, and ideally without using DLLs. Something like: UnzipTree ('C:\input\data.zip', 'C:\DestinationDiectory', [opOverwriteExisting]); with any subdirectory structure in data.zip being mirrored in the destination directory. What simple, easy-to-use method would you recommend for the task? Thanks, David > {quote:title=David Taylor wrote:}{quote} > Using Delphi 2009, I need to unzip a tree of files in a Zip ...

Using Code behind without VS.NET
Hello,I read the asp101.com tutorial on accomplishing the code behind feature without using Visual Studio.NET and have tried to implement it into a small uploader script tutorial I've been following.  Here is the code of the two pages I have so far:upload.aspx<%@ Page Language="vb" AutoEventWireup="false" Src="upload.aspx.vb" Inherits="upload"%> <Html> <Head> <Title>PDF Upload</Title> </Head> <Body>      <Font Color="DarkGreen" Face="Helvetica" Size="5"><B>Upload file to a folder</B></Font>&l...

C# scipting implementation using code behind
I'm trying to make a web page template using a script that determines content based on cookie values. I'm using aspx with code behind. How do I call methods from the class in the code behind file through a script tag to, say, insert a table or some other tags? I don't want to use a c# script that is included in the html of the web page because we may have to change this in the future. This can be done easily with Javascript but I don't think our cookies can be read by Javascript as we encrypt the content. Thanks in advance....

Web resources about - Implementing a TIdCmdTCPServer without using reply codes - embarcadero.delphi.winsock

Resources last updated: 1/9/2016 8:26:11 PM