Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Mar : Re: Creating TCP server with blocking Indy components?
| Subject: | Re: Creating TCP server with blocking Indy components? |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Fri, 23 Mar 2007 09:40:43 |
"Bo Berglund" <bo.berglund@telia.com> wrote in message
news:ftt603hu6g6s9puc7plo3891am2mss9669@4ax.com...
> Is there any docs besides the help file in Delphi7?
Indy has its own documentation that you can download from Indy's
website, or view online.
> In the example of the server I found only some administrative
> actions in the ServerConnect method:
That has nothing to do with what you are asking for.
> How do I actually send something back to the client here?
Again, read the documentation. TIdPeerThread has a Connection
property of type TIdTCPConnection, which has all kinds of reading and
writing methods available.
> >Everything you can do in TServerSocket can be done in TIdTCPServer
as
> >well.
>
> I hope so, but when I read the introduction here:
> http://www.swissdelphicenter.ch/en/showarticle.php?id=4
> it talks a lot about the blocking ways and unix...
That has no bearing on this discussion. It does not matter whether
the sockets are blocking or non-blocking. Data is data.
> Is this the way to send the data:
> AThread.Connection.WriteLn('Indy Zip Code Server Ready.');
Yes, assuming that you want the string to include a CRLF at the end.
> What happens if I don't want to have the line endings (my data
> contain line endings but are not ended by suc, there are many
> lines in a packet?
Then use Write() instead. It sends the string as-is.
> OK, so OnExecute is an event that gets fired when?
Repeatedly in an endless loop for the lifetime of the connection.
Again, read the documentation.
> As soon as some data have arrived
No.
> when the complete chunk of data from the client has arrived?
No.
> Sometimes the data are sizeable, over the command channel I
> can request data and this is then sent over the "state" channel
> and can be many kilobytes (all in XML).
That is where Indy's blocking nature helps you. All you have to do is
tell it how many bytes to read, or specify the desired end-of-data
terminator, and Indy will handle all of the waiting and buffering for
you until all of the expected data has arrived.
> Yes, but what about the packet ending? I understand that you
> must tell Indy which character is the ending character of a
> message and in this case there is none.
Yes, there is - the closing tag of the XML. A terminator does not
have to be a single character. It can be a variable-length string.
> The only close thing I have is the end tag (6 chars).
Which is perfectly fine. Indy can handle that.
> So it is not a single character that can be specified as the ending
> char like LF or CR....
It doesn't have to be.
> How can I get hold of that object? Is it a property of AThread?
> (AThread.Connection)???
Yes.
> what I need to read is a complte string of an XML messsage packet.
> No fixed data types and no terminating character (see above).
See above.
> Development snapshot sounds like an unstable beta. Can it be
> used also for production code?
Yes.
> This server must not allow more than one client to connect in
> order not to mix up the machine tools. How can I separate them
> by disallowing a connect if one is already established?
TIdTCPServer has a MaxConnections property that handles that
automatically. Simply set it to 1.
However, under such a restrictive limit, you might conside using
TIdSimpleServer instead, as it only allows 1 client connection at a
time. But TIdSimpleServer is not a threaded component, so it has no
events of its own. It was designed for simple connections (hense the
name) that can read/write inlined with other code.
Gambit