 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Bo Berglund Guest
|
Posted: Fri Feb 03, 2006 7:29 pm Post subject: How do I use TIdTCPClient in nonblocking mode using D7? |
|
|
I have been using TClientSocket for ages since the Delphi 4 or 5 days
but I'm now using Delphi 7 where this component is depreciated in
favour of Indy, which is installed by default with D7.
So I tried to use the TIdTCPClient in my new project instead, but I
have real trouble understanding it. :-(
What I want to accomplish is simply to hook up two applications over
the network from one location to the other. One side will basically be
a port server where an RS232 channel is established with an external
system and the task is to relay *all* of the data sent by the external
system to the listening application.
There is absolutely no knowledge of when data will start streaming
from the equipment, we may even be shutting down the connection
without receiving a single byte.
This is to me a perfect case of having *event driven* code like this:
SERVER SIDE
------------
The ApdComport component generates an event when data arrives on the
RS232 line. In this event the server will receive the data and send it
to the socket if it is connected at the time.
(using TClientSocket.Socket.SendText)
That's all.
CLIENT SIDE
------------
When the client starts up it establishes a socket connection to the
server. Then in the OnRead event the data arriving over the network is
put into a buffer which is later processed.
When there are no data arriving the client is idle.
This was easy to do using the TClientSocket component but seems
completely impossible with TIdTCPClient...
The only way I have found to get data from the TIdTCPClient is to use
its ReadString method. But how can I know *when* to call ReadString???
There is no OnReceive event to hook it to! If I just call it randomly
then my application locks up inside the method...
And another problem, ReadString has a parameter telling it how many
bytes to read, but that is unknown! How can the client know how many
bytes the server is going to send??? The data are normally packaged
into packets delimited by STX and ETX but these can also appear inside
the contents and are then doubled. There is no other limtation,
packets can be of arbitrary length for example.
Unfortunately in true Delphi style of course there are no examples
referenced in the help either....
Can anyone explain this?
/Bo
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|